#include <bits/stdc++.h>
using namespace std;
const int N = 2e5, Q = 1e6;
int n, q, a[N], b[N], ans[Q];
tuple<int, int, int> qry[Q];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
y--;
qry[i] = make_tuple(x, y, i);
}
sort(qry, qry+q);
int curr = 0;
bool same = 0;
for (int i = 0; i < q; i++) {
while (!same && curr < get<0>(qry[i])) {
curr++;
int l = 0;
int r = n/2;
int x = 0;
while (l < n/2 && r < n) {
if (a[l] < a[r]) {
b[x++] = a[l++];
}
else {
b[x++] = a[r++];
}
}
while (l < n/2) {
b[x++] = a[l++];
}
bool ok = 1;
for (int i = 0; i < r; i++) {
if (a[i] != b[i]) ok = 0;
a[i] = b[i];
}
if (ok) same = 1;
}
ans[get<2>(qry[i])] = a[get<1>(qry[i])];
}
for (int i = 0; i < q; i++) {
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
24912 KB |
Output is correct |
2 |
Correct |
261 ms |
24912 KB |
Output is correct |
3 |
Correct |
249 ms |
24460 KB |
Output is correct |
4 |
Correct |
257 ms |
24072 KB |
Output is correct |
5 |
Correct |
253 ms |
24688 KB |
Output is correct |
6 |
Correct |
245 ms |
24308 KB |
Output is correct |
7 |
Correct |
253 ms |
24624 KB |
Output is correct |
8 |
Correct |
245 ms |
24144 KB |
Output is correct |
9 |
Correct |
242 ms |
24012 KB |
Output is correct |
10 |
Correct |
249 ms |
24200 KB |
Output is correct |
11 |
Correct |
242 ms |
24148 KB |
Output is correct |
12 |
Correct |
243 ms |
23632 KB |
Output is correct |
13 |
Correct |
253 ms |
23936 KB |
Output is correct |
14 |
Correct |
251 ms |
24304 KB |
Output is correct |
15 |
Correct |
261 ms |
24008 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
230 ms |
23840 KB |
Output is correct |
18 |
Correct |
244 ms |
23684 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3033 ms |
22876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3046 ms |
8024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
251 ms |
24912 KB |
Output is correct |
2 |
Correct |
261 ms |
24912 KB |
Output is correct |
3 |
Correct |
249 ms |
24460 KB |
Output is correct |
4 |
Correct |
257 ms |
24072 KB |
Output is correct |
5 |
Correct |
253 ms |
24688 KB |
Output is correct |
6 |
Correct |
245 ms |
24308 KB |
Output is correct |
7 |
Correct |
253 ms |
24624 KB |
Output is correct |
8 |
Correct |
245 ms |
24144 KB |
Output is correct |
9 |
Correct |
242 ms |
24012 KB |
Output is correct |
10 |
Correct |
249 ms |
24200 KB |
Output is correct |
11 |
Correct |
242 ms |
24148 KB |
Output is correct |
12 |
Correct |
243 ms |
23632 KB |
Output is correct |
13 |
Correct |
253 ms |
23936 KB |
Output is correct |
14 |
Correct |
251 ms |
24304 KB |
Output is correct |
15 |
Correct |
261 ms |
24008 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
230 ms |
23840 KB |
Output is correct |
18 |
Correct |
244 ms |
23684 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Execution timed out |
3033 ms |
22876 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |