#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> f(vector<int>& v) {
vector<int> a;
int i = 0, j = n / 2;
while (i < n / 2 && j < n) {
if (v[i] < v[j]) a.push_back(v[i++]);
else a.push_back(v[j++]);
}
while (i < n / 2) a.push_back(v[i++]);
while (j < n) a.push_back(v[j++]);
return a;
}
signed main() {
cin >> n >> q;
vector<int> v(n);
for (auto& i : v) cin >> i;
vector<vector<int>> ans(n + 1);
ans[0] = v;
for (int i = 1; i <= n; ++i) ans[i] = f(ans[i - 1]);
while (q--) {
int t, i;
cin >> t >> i;
t = min(t, n);
cout << ans[t][i - 1] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1577 ms |
16048 KB |
Output is correct |
2 |
Correct |
1488 ms |
15712 KB |
Output is correct |
3 |
Correct |
1421 ms |
15260 KB |
Output is correct |
4 |
Correct |
1445 ms |
14392 KB |
Output is correct |
5 |
Correct |
1468 ms |
15536 KB |
Output is correct |
6 |
Correct |
1413 ms |
14416 KB |
Output is correct |
7 |
Correct |
1470 ms |
15808 KB |
Output is correct |
8 |
Correct |
1434 ms |
14672 KB |
Output is correct |
9 |
Correct |
1400 ms |
14500 KB |
Output is correct |
10 |
Correct |
1504 ms |
14340 KB |
Output is correct |
11 |
Correct |
1462 ms |
14644 KB |
Output is correct |
12 |
Correct |
1374 ms |
13472 KB |
Output is correct |
13 |
Correct |
1429 ms |
14168 KB |
Output is correct |
14 |
Correct |
1473 ms |
14888 KB |
Output is correct |
15 |
Correct |
1462 ms |
14596 KB |
Output is correct |
16 |
Correct |
5 ms |
4440 KB |
Output is correct |
17 |
Correct |
1431 ms |
13852 KB |
Output is correct |
18 |
Correct |
1430 ms |
13444 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
632 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
611 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1577 ms |
16048 KB |
Output is correct |
2 |
Correct |
1488 ms |
15712 KB |
Output is correct |
3 |
Correct |
1421 ms |
15260 KB |
Output is correct |
4 |
Correct |
1445 ms |
14392 KB |
Output is correct |
5 |
Correct |
1468 ms |
15536 KB |
Output is correct |
6 |
Correct |
1413 ms |
14416 KB |
Output is correct |
7 |
Correct |
1470 ms |
15808 KB |
Output is correct |
8 |
Correct |
1434 ms |
14672 KB |
Output is correct |
9 |
Correct |
1400 ms |
14500 KB |
Output is correct |
10 |
Correct |
1504 ms |
14340 KB |
Output is correct |
11 |
Correct |
1462 ms |
14644 KB |
Output is correct |
12 |
Correct |
1374 ms |
13472 KB |
Output is correct |
13 |
Correct |
1429 ms |
14168 KB |
Output is correct |
14 |
Correct |
1473 ms |
14888 KB |
Output is correct |
15 |
Correct |
1462 ms |
14596 KB |
Output is correct |
16 |
Correct |
5 ms |
4440 KB |
Output is correct |
17 |
Correct |
1431 ms |
13852 KB |
Output is correct |
18 |
Correct |
1430 ms |
13444 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Runtime error |
632 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |