#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> shf(vector<int> v) {
vector<int> ans;
int m = n/2;
int p1 = 0, p2 = m;
while ((p1 < m) || (p2 < n)) {
if (p1 == m) {
ans.push_back(v[p2]);
p2++;
continue;
}
if (p2 == n) {
ans.push_back(v[p1]);
p1++;
continue;
}
if (v[p1] < v[p2]) {
ans.push_back(v[p1]);
p1++;
} else {
ans.push_back(v[p2]);
p2++;
}
}
return ans;
}
#define pii pair<int, int>
#define fr first
#define se second
int32_t main() {
int q;
cin >> n >> q;
vector<int> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<pair<pii, int>> queries(q);
vector<int> ans(q);
for (int i = 0; i < q; i++) {
cin >> queries[i].fr.fr >> queries[i].fr.se;
queries[i].se = i;
}
sort(queries.begin(), queries.end());
int t = 0;
bool done = 0;
for (auto u : queries) {
while ((u.fr.fr > t) && !done) {
vector<int> novo = shf(s);
if (novo == s) {
done = 1;
} else {
s = novo;
}
t++;
}
ans[u.se] = s[u.fr.se - 1];
}
for (auto u : ans) cout << u << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
27592 KB |
Output is correct |
2 |
Correct |
400 ms |
27336 KB |
Output is correct |
3 |
Correct |
375 ms |
26440 KB |
Output is correct |
4 |
Correct |
396 ms |
25160 KB |
Output is correct |
5 |
Correct |
451 ms |
26952 KB |
Output is correct |
6 |
Correct |
419 ms |
25320 KB |
Output is correct |
7 |
Correct |
434 ms |
27108 KB |
Output is correct |
8 |
Correct |
402 ms |
25672 KB |
Output is correct |
9 |
Correct |
390 ms |
25160 KB |
Output is correct |
10 |
Correct |
427 ms |
25680 KB |
Output is correct |
11 |
Correct |
379 ms |
25672 KB |
Output is correct |
12 |
Correct |
398 ms |
24508 KB |
Output is correct |
13 |
Correct |
412 ms |
25496 KB |
Output is correct |
14 |
Correct |
440 ms |
26184 KB |
Output is correct |
15 |
Correct |
439 ms |
26184 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
390 ms |
24768 KB |
Output is correct |
18 |
Correct |
396 ms |
24648 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3060 ms |
33976 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3033 ms |
5424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
27592 KB |
Output is correct |
2 |
Correct |
400 ms |
27336 KB |
Output is correct |
3 |
Correct |
375 ms |
26440 KB |
Output is correct |
4 |
Correct |
396 ms |
25160 KB |
Output is correct |
5 |
Correct |
451 ms |
26952 KB |
Output is correct |
6 |
Correct |
419 ms |
25320 KB |
Output is correct |
7 |
Correct |
434 ms |
27108 KB |
Output is correct |
8 |
Correct |
402 ms |
25672 KB |
Output is correct |
9 |
Correct |
390 ms |
25160 KB |
Output is correct |
10 |
Correct |
427 ms |
25680 KB |
Output is correct |
11 |
Correct |
379 ms |
25672 KB |
Output is correct |
12 |
Correct |
398 ms |
24508 KB |
Output is correct |
13 |
Correct |
412 ms |
25496 KB |
Output is correct |
14 |
Correct |
440 ms |
26184 KB |
Output is correct |
15 |
Correct |
439 ms |
26184 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
390 ms |
24768 KB |
Output is correct |
18 |
Correct |
396 ms |
24648 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Execution timed out |
3060 ms |
33976 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |