Lilin_ @ 2023-08-19 11:22:45
#include<bits/stdc++.h>
using namespace std;
long long a[2500000],b[2500001];
int main(){
int n=0,k=0;
cin>>n>>k;
if(n>2500000){
for(int i=0;i<2500000;i++){
scanf("%lld",&a[i]);
}
sort(a,a+2500000);
for(int i=0;i<n-2500000;i++){
scanf("%lld",&b[i]);
}
sort(b,b+(n-2500000));
if(k>2500000) cout<<b[k-2500000];
else cout<<a[k];
}
else{
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
sort(a,a+n);
cout<<a[k];
}
}
by siuuuuu @ 2023-08-19 11:41:56
#include<iostream>
#include<algorithm>
const int maxn=1e6*5+10;
using namespace std;
int k,n,a[maxn];
void qsort(int s,int e){
int mid=(s+e)/2,flag=a[mid],l=s,r=e;
do{
while(a[l]<flag)l++;
while(a[r]>flag)r--;
if(l<=r){
swap(a[l],a[r]);
l++;
r--;
}
}while(l<=r);
if(k<=r){
if(s<r)qsort(s,r);
else return;
}else if(k>=l){
if(l<e)qsort(l,e);
else return;
}
return;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
qsort(0,n-1);
cout<<a[k];
return 0;
}
我不应该帮诈骗犯的
by Lilin_ @ 2023-08-20 20:00:47
@niganmaaiyou 没看到,不好意思,谢谢dalaoQAQ
Never gonna give you up