#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int n, q;
cin >> n >> q;
vector <int> v;
for(int i = 1;i <= n;i++){
int x;
cin >> x;
v.push_back(x);
}
vector <array <int, 3>> query;
for(int i = 1;i <= q;i++){
int a, b;
cin >> a >> b;
query.push_back({a, b, i});
}
sort(query.begin(), query.end());
map <array <int, 3>, int> resp;
map <vector <int>, int> mark;
int st = 0;
bool ac = true;
for(auto x : query){
while(st < x[0] and ac){
mark[v] = 1;
vector <int> a, b;
for(int i = 0;i < n/2;i++){
a.push_back(v[i]);
}
for(int i = n/2;i < n;i++){
b.push_back(v[i]);
}
vector <int> next;
int l = 0, r = 0;
while(l < n/2 or r < n/2){
if(r == n/2){
swap(a, b);
swap(l, r);
}
if(l == n/2){
for(int i = r;i < n/2;i++){
next.push_back(b[i]);
}
}
if(a[l] < b[r]){
next.push_back(a[l]);
l++;
}
else{
next.push_back(b[r]);
r++;
}
}
if(mark[next] == 1) ac = false;
st++;
v = next;
}
resp[x] = v[x[1]-1];
}
for(auto &x : query){
swap(x[0], x[2]);
}
sort(query.begin(), query.end());
for(auto x : query){
cout << resp[{x[2], x[1], x[0]}] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1429 ms |
85924 KB |
Output is correct |
2 |
Correct |
1420 ms |
81468 KB |
Output is correct |
3 |
Correct |
1398 ms |
78952 KB |
Output is correct |
4 |
Correct |
1337 ms |
75444 KB |
Output is correct |
5 |
Correct |
1409 ms |
79160 KB |
Output is correct |
6 |
Correct |
1349 ms |
77244 KB |
Output is correct |
7 |
Correct |
1458 ms |
79732 KB |
Output is correct |
8 |
Correct |
1366 ms |
78376 KB |
Output is correct |
9 |
Correct |
1367 ms |
75240 KB |
Output is correct |
10 |
Correct |
1340 ms |
76844 KB |
Output is correct |
11 |
Correct |
1392 ms |
77652 KB |
Output is correct |
12 |
Correct |
1163 ms |
75432 KB |
Output is correct |
13 |
Correct |
1322 ms |
78120 KB |
Output is correct |
14 |
Correct |
1424 ms |
79228 KB |
Output is correct |
15 |
Correct |
1430 ms |
80144 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1150 ms |
77468 KB |
Output is correct |
18 |
Correct |
1092 ms |
75308 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1983 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1961 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1429 ms |
85924 KB |
Output is correct |
2 |
Correct |
1420 ms |
81468 KB |
Output is correct |
3 |
Correct |
1398 ms |
78952 KB |
Output is correct |
4 |
Correct |
1337 ms |
75444 KB |
Output is correct |
5 |
Correct |
1409 ms |
79160 KB |
Output is correct |
6 |
Correct |
1349 ms |
77244 KB |
Output is correct |
7 |
Correct |
1458 ms |
79732 KB |
Output is correct |
8 |
Correct |
1366 ms |
78376 KB |
Output is correct |
9 |
Correct |
1367 ms |
75240 KB |
Output is correct |
10 |
Correct |
1340 ms |
76844 KB |
Output is correct |
11 |
Correct |
1392 ms |
77652 KB |
Output is correct |
12 |
Correct |
1163 ms |
75432 KB |
Output is correct |
13 |
Correct |
1322 ms |
78120 KB |
Output is correct |
14 |
Correct |
1424 ms |
79228 KB |
Output is correct |
15 |
Correct |
1430 ms |
80144 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1150 ms |
77468 KB |
Output is correct |
18 |
Correct |
1092 ms |
75308 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Runtime error |
1983 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |