点名
70分暴力:
源代码: #include<cstdio> #define LL long long LL m,n,Sign,i[30001]; void Read(LL &t) //读入优化,我已献上一切。 { t=0; char T=getchar(); while (T<'0'||T>'9') T=getchar(); while (T>='0'&&T<='9') { t=t*10+T-'0'; T=getchar(); } } void Qsort(LL t1,LL t2) //修改快排。 { LL X=t1,Y=t2,T=i[(t1+t2)>>1],t; do { while (i[X]<T) X++; while (i[Y]>T) Y--; if (X<=Y) { t=i[X]; i[X]=i[Y]; i[Y]=t; X++; Y--; } } while (X<=Y); if (X<=Sign&&X<t2) Qsort(X,t2); if (Y>=Sign&&t1<Y) Qsort(t1,Y); } int main() { Read(n); Read(m); for (LL a=1;a<=n;a++) Read(i[a]); for (LL b=1;b<=m;b++) { LL T; Sign=b; Read(T); Qsort(1,T); printf("%I64d\n",i[Sign]); } return 0; }