分类: C/C++
2008-03-08 01:28:36
#includestruct node { int da; int po; }node[100005],temp[100005]; void MergeSort(int left,int right) { int i,j,k,mid; if(left==right) return ; mid=(left+right)/2; MergeSort(left,mid); MergeSort(mid+1,right); i=left,j=mid+1,k=left; while(i<=mid&&j<=right) { if(node[i].da<node[j].da) temp[k++]=node[i++]; else temp[k++]=node[j++]; } while(i<=mid) temp[k++]=node[i++]; while(j<=right) temp[k++]=node[j++]; for(i=left;i<=right;i++) node[i]=temp[i]; } int main() { int i,j,k,m,n,r,rr,kk; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=n;i++) { scanf("%d",&node[i].da); node[i].po=i; } MergeSort(1,n); for(r=1;r<=m;r++) { scanf("%d%d%d",&i,&j,&k); kk=0; for(rr=1;rr<=n&&kk<k;rr++) { if(node[rr].po<i||node[rr].po>j) continue; kk++; } printf("%d\n",node[rr-1].da); } } }