haust_dingbang @ 2021-03-15 20:15:13
无语了,我都已经分治了,用了全局变量了,结果还给我超时,然后才看到题解中说要用快读,我。。。换了好几种方式,先是std::sort,然后自己写个优先队列,然后分治(快速排序类似),我都想用基数排序了,嘤嘤嘤
by BlachSnake @ 2021-03-15 20:32:03
@王熙文 %%%
by ud2_ @ 2021-03-15 20:38:55
谁说 STL 慢?
/record/47912302
by tribool4_in @ 2021-03-15 20:47:41
光 速 读
by haust_dingbang @ 2021-03-25 17:50:22
好家伙,各位每次写个程序前面添加这么多东西吗,太多了看着不太舒服
by ChinozoX_X @ 2021-04-06 13:45:41
#include<iostream>
#include<cstdio>
using namespace std;
int n,k;
int a[5000010],ans=0;
void findk(int a[],int l,int r){
if(l==r){
ans=a[l];
return ;
}
int i = l, j = r, flag = a[(l + r) / 2], tmp;
do {
while (a[i] < flag) {
i++;
}
while (a[j] > flag) {
j--;
}
if (i <= j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
} while (i <= j);
if(k+1<=j)
findk(a,l,j);
else if(k+1>=i)
findk(a,i,r);
else
findk(a,j+1,i-1);
return ;
}
int main() {
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
findk(a,1,n);
cout<<ans;
return 0;
}
by _Veritas @ 2021-05-13 10:11:37
inline int read(){
int x=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') x=x*10+c-'0';c=getchar();
return x;
}