#include<bits/stdc++.h>
using namespace std;
int main(){
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;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 |
1516 ms |
101464 KB |
Output is correct |
2 |
Correct |
1609 ms |
95612 KB |
Output is correct |
3 |
Correct |
1411 ms |
86112 KB |
Output is correct |
4 |
Correct |
1518 ms |
78856 KB |
Output is correct |
5 |
Correct |
1529 ms |
83756 KB |
Output is correct |
6 |
Correct |
1460 ms |
80048 KB |
Output is correct |
7 |
Correct |
1548 ms |
84208 KB |
Output is correct |
8 |
Correct |
1563 ms |
142748 KB |
Output is correct |
9 |
Correct |
1523 ms |
79524 KB |
Output is correct |
10 |
Correct |
1467 ms |
80688 KB |
Output is correct |
11 |
Correct |
1481 ms |
153496 KB |
Output is correct |
12 |
Correct |
1421 ms |
78508 KB |
Output is correct |
13 |
Correct |
1571 ms |
143732 KB |
Output is correct |
14 |
Correct |
1664 ms |
154952 KB |
Output is correct |
15 |
Correct |
1688 ms |
82140 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1318 ms |
85808 KB |
Output is correct |
18 |
Correct |
1350 ms |
85616 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1979 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
924 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1516 ms |
101464 KB |
Output is correct |
2 |
Correct |
1609 ms |
95612 KB |
Output is correct |
3 |
Correct |
1411 ms |
86112 KB |
Output is correct |
4 |
Correct |
1518 ms |
78856 KB |
Output is correct |
5 |
Correct |
1529 ms |
83756 KB |
Output is correct |
6 |
Correct |
1460 ms |
80048 KB |
Output is correct |
7 |
Correct |
1548 ms |
84208 KB |
Output is correct |
8 |
Correct |
1563 ms |
142748 KB |
Output is correct |
9 |
Correct |
1523 ms |
79524 KB |
Output is correct |
10 |
Correct |
1467 ms |
80688 KB |
Output is correct |
11 |
Correct |
1481 ms |
153496 KB |
Output is correct |
12 |
Correct |
1421 ms |
78508 KB |
Output is correct |
13 |
Correct |
1571 ms |
143732 KB |
Output is correct |
14 |
Correct |
1664 ms |
154952 KB |
Output is correct |
15 |
Correct |
1688 ms |
82140 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1318 ms |
85808 KB |
Output is correct |
18 |
Correct |
1350 ms |
85616 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Runtime error |
1979 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |