#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define chmin(a,b) a=(a<b?a:b)
#define chmax(a,b) a=(a>b?a:b)
//#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=3005;
const int INF=1e9;
int32_t main() {
LCBorz;
int n,q;cin>>n>>q;
vector<int> v(n),v1;
for(int i=0;i<n;i++){
cin>>v[i];
}
vector<vector<int>> rec;
rec.push_back(v);
while(1){
int i=0,j=n/2;
while(i<n/2&&j<n){
if(v[i]<v[j]){
v1.push_back(v[i++]);
}
else{
v1.push_back(v[j++]);
}
}
while(i<n/2){
v1.push_back(v[i++]);
}
while(j<n){
v1.push_back(v[j++]);
}
v=v1;
v1.clear();
if(rec.back()==v){
break;
}
rec.push_back(v);
}
int sz=rec.size();
for(int i=0;i<q;i++){
int p,x;cin>>p>>x;
p=min(sz-1,p);
cout<<rec[p][x-1]<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
15952 KB |
Output is correct |
2 |
Correct |
164 ms |
12628 KB |
Output is correct |
3 |
Correct |
157 ms |
13140 KB |
Output is correct |
4 |
Correct |
152 ms |
10376 KB |
Output is correct |
5 |
Correct |
203 ms |
12064 KB |
Output is correct |
6 |
Correct |
157 ms |
10844 KB |
Output is correct |
7 |
Correct |
165 ms |
12292 KB |
Output is correct |
8 |
Correct |
150 ms |
10760 KB |
Output is correct |
9 |
Correct |
170 ms |
10580 KB |
Output is correct |
10 |
Correct |
201 ms |
10832 KB |
Output is correct |
11 |
Correct |
166 ms |
10904 KB |
Output is correct |
12 |
Correct |
147 ms |
9708 KB |
Output is correct |
13 |
Correct |
171 ms |
10320 KB |
Output is correct |
14 |
Correct |
158 ms |
11480 KB |
Output is correct |
15 |
Correct |
163 ms |
10660 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
152 ms |
9832 KB |
Output is correct |
18 |
Correct |
151 ms |
9552 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
511 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
395 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
170 ms |
15952 KB |
Output is correct |
2 |
Correct |
164 ms |
12628 KB |
Output is correct |
3 |
Correct |
157 ms |
13140 KB |
Output is correct |
4 |
Correct |
152 ms |
10376 KB |
Output is correct |
5 |
Correct |
203 ms |
12064 KB |
Output is correct |
6 |
Correct |
157 ms |
10844 KB |
Output is correct |
7 |
Correct |
165 ms |
12292 KB |
Output is correct |
8 |
Correct |
150 ms |
10760 KB |
Output is correct |
9 |
Correct |
170 ms |
10580 KB |
Output is correct |
10 |
Correct |
201 ms |
10832 KB |
Output is correct |
11 |
Correct |
166 ms |
10904 KB |
Output is correct |
12 |
Correct |
147 ms |
9708 KB |
Output is correct |
13 |
Correct |
171 ms |
10320 KB |
Output is correct |
14 |
Correct |
158 ms |
11480 KB |
Output is correct |
15 |
Correct |
163 ms |
10660 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
152 ms |
9832 KB |
Output is correct |
18 |
Correct |
151 ms |
9552 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Runtime error |
511 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |