#include <bits/stdc++.h>
using namespace std;
void riffle_shuffle(vector<int> &a) {
vector<int> L(a.begin(), a.begin() + a.size() / 2);
vector<int> R(a.begin() + a.size() / 2, a.end());
int i = 0, j = 0;
int n = a.size() / 2;
while (i < n || j < n) {
if (i != n && (j == n || L[i] < R[j])) {
a[j + i] = L[i];
i += 1;
} else {
a[j + i] = R[j];
j += 1;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int &x : a) {
cin >> x;
}
vector<array<int, 3>> queries(q);
for (int i = 0; i < q; ++i) {
cin >> queries[i][0] >> queries[i][1];
queries[i][2] = i;
}
sort(queries.begin(), queries.end());
vector<int> ans(q, -1);
int pnt = 0;
for (int _ = 0; ; ++_) {
while (pnt < q && queries[pnt][0] == _) {
ans[queries[pnt][2]] = a[queries[pnt][1] - 1];
pnt += 1;
}
if (pnt == q) {
break;
}
auto prv = a;
riffle_shuffle(a);
assert(_ <= n / 2);
if (prv == a) {
while (pnt < q) {
ans[queries[pnt][2]] = a[queries[pnt][1] - 1];
pnt += 1;
}
break;
}
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
297 ms |
32164 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3077 ms |
18796 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3074 ms |
3892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
297 ms |
32164 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |