蓝桥杯 算法训练 区间k大数查询
参考:https://www.cnblogs.com/yym2013/p/3509166.html
https://www.cnblogs.com/hemeiwolong/p/8994986.html
https://blog.csdn.net/e_one/article/details/80676166
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 // freopen("in.txt","r",stdin); 6 int n,m,in[1005],temp[1005]; 7 cin>>n; 8 for (int i=1;i<=n;i++) 9 { 10 cin>>in[i]; 11 } 12 // cout<<"yuan:"<<endl; 13 // for (int i=1;i<=n;i++) 14 // { 15 // cout<<in[i]<<" "; 16 // } 17 // cout<<endl; 18 cin>>m; 19 while (m--) 20 { 21 int l,r,k; 22 cin>>l>>r>>k; 23 for (int i=l;i<=r;i++) 24 { 25 temp[i]=in[i]; 26 } 27 // cout<<"yuan temp"<<endl; 28 // for (int i=l;i<=r;i++) 29 // { 30 // cout<<temp[i]<<" "; 31 // } 32 // cout<<endl; 33 sort(temp+l,temp+r+1);//要注意起始位置!! 34 // cout<<"change temp"<<endl; 35 // for (int i=l;i<=r;i++) 36 // { 37 // cout<<temp[i]<<" "; 38 // } 39 // cout<<endl; 40 cout<<temp[r-k+1]<<endl; 41 } 42 43 return 0; 44 }