#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#include "debug.cpp"
#else
#define debug(...)
#endif
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);
int n,q;
cin>>n>>q;
deque<int> v;
vector<vector<int>> ver;
ver.push_back({});
for(int i = 0;i<n;i++){
int x;cin>>x;
ver[0].push_back(x);
v.push_back(x);
}
while(1){
deque<int> p1,p2,all;
int x = n/2;
while(x--){
p1.push_back(v[0]);v.pop_front();
}
x = n/2;
while(x--){
p2.push_back(v[0]);v.pop_front();
}
while(p1.size()&&p2.size()){
if(p1[0]<p2[0]){
all.push_back(p1[0]);p1.pop_front();
}else{
all.push_back(p2[0]);p2.pop_front();
}
}
while(p1.size()){
all.push_back(p1[0]);p1.pop_front();
}while(p2.size()){
all.push_back(p2[0]);p2.pop_front();
}
swap(v,all);bool ss = 0;
for(int i = 0;i<n;i++){
if(ver.back()[i]!=v[i]){
ss = 1;
}
}
if(!ss)break;
ver.push_back({});
for(int i = 0;i<n;i++){
ver.back().push_back(v[i]);
}
}
while(q--){
int a,b;cin>>a>>b;
a = min(a,(int)ver.size()-1);
cout<<ver[a][b-1]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1222 ms |
14120 KB |
Output is correct |
2 |
Correct |
1247 ms |
12796 KB |
Output is correct |
3 |
Correct |
1164 ms |
13444 KB |
Output is correct |
4 |
Correct |
1176 ms |
10500 KB |
Output is correct |
5 |
Correct |
1211 ms |
11948 KB |
Output is correct |
6 |
Correct |
1164 ms |
10976 KB |
Output is correct |
7 |
Correct |
1210 ms |
12552 KB |
Output is correct |
8 |
Correct |
1272 ms |
10876 KB |
Output is correct |
9 |
Correct |
1142 ms |
10460 KB |
Output is correct |
10 |
Correct |
1168 ms |
11048 KB |
Output is correct |
11 |
Correct |
1169 ms |
10676 KB |
Output is correct |
12 |
Correct |
1141 ms |
9712 KB |
Output is correct |
13 |
Correct |
1219 ms |
10388 KB |
Output is correct |
14 |
Correct |
1184 ms |
11396 KB |
Output is correct |
15 |
Correct |
1240 ms |
10664 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1236 ms |
9896 KB |
Output is correct |
18 |
Correct |
1154 ms |
9736 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1952 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1795 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1222 ms |
14120 KB |
Output is correct |
2 |
Correct |
1247 ms |
12796 KB |
Output is correct |
3 |
Correct |
1164 ms |
13444 KB |
Output is correct |
4 |
Correct |
1176 ms |
10500 KB |
Output is correct |
5 |
Correct |
1211 ms |
11948 KB |
Output is correct |
6 |
Correct |
1164 ms |
10976 KB |
Output is correct |
7 |
Correct |
1210 ms |
12552 KB |
Output is correct |
8 |
Correct |
1272 ms |
10876 KB |
Output is correct |
9 |
Correct |
1142 ms |
10460 KB |
Output is correct |
10 |
Correct |
1168 ms |
11048 KB |
Output is correct |
11 |
Correct |
1169 ms |
10676 KB |
Output is correct |
12 |
Correct |
1141 ms |
9712 KB |
Output is correct |
13 |
Correct |
1219 ms |
10388 KB |
Output is correct |
14 |
Correct |
1184 ms |
11396 KB |
Output is correct |
15 |
Correct |
1240 ms |
10664 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1236 ms |
9896 KB |
Output is correct |
18 |
Correct |
1154 ms |
9736 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Runtime error |
1952 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |