#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 1004;
int A[MAX][MAX];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, Q;
cin >> N >> Q;
for (int i = 1; i <= N; ++i) cin >> A[0][i];
for (int t = 1; t < MAX; ++t) {
int a = 1, b = (N / 2) + 1, idx = 1;
while (a <= N / 2 || b <= N) {
if (N < b) A[t][idx++] = A[t - 1][a++];
else if (N / 2 < a) A[t][idx++] = A[t - 1][b++];
else A[t][idx++] = A[t - 1][(A[t - 1][a] < A[t - 1][b] ? a : b)++];
}
}
for (int i = 1; i <= Q; ++i) {
int a, b;
cin >> a >> b;
a = min(a, MAX - 1);
cout << A[a][b] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
8280 KB |
Output is correct |
2 |
Correct |
142 ms |
15484 KB |
Output is correct |
3 |
Correct |
162 ms |
15156 KB |
Output is correct |
4 |
Correct |
131 ms |
14160 KB |
Output is correct |
5 |
Correct |
140 ms |
15188 KB |
Output is correct |
6 |
Correct |
128 ms |
14416 KB |
Output is correct |
7 |
Correct |
145 ms |
15412 KB |
Output is correct |
8 |
Correct |
149 ms |
14344 KB |
Output is correct |
9 |
Correct |
141 ms |
14220 KB |
Output is correct |
10 |
Correct |
146 ms |
14468 KB |
Output is correct |
11 |
Correct |
142 ms |
14480 KB |
Output is correct |
12 |
Correct |
164 ms |
13488 KB |
Output is correct |
13 |
Correct |
145 ms |
14092 KB |
Output is correct |
14 |
Correct |
139 ms |
14856 KB |
Output is correct |
15 |
Correct |
158 ms |
14420 KB |
Output is correct |
16 |
Correct |
3 ms |
4188 KB |
Output is correct |
17 |
Correct |
118 ms |
13588 KB |
Output is correct |
18 |
Correct |
143 ms |
13632 KB |
Output is correct |
19 |
Correct |
1 ms |
4188 KB |
Output is correct |
20 |
Correct |
1 ms |
4188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
182 ms |
8528 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
110 ms |
8584 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
8280 KB |
Output is correct |
2 |
Correct |
142 ms |
15484 KB |
Output is correct |
3 |
Correct |
162 ms |
15156 KB |
Output is correct |
4 |
Correct |
131 ms |
14160 KB |
Output is correct |
5 |
Correct |
140 ms |
15188 KB |
Output is correct |
6 |
Correct |
128 ms |
14416 KB |
Output is correct |
7 |
Correct |
145 ms |
15412 KB |
Output is correct |
8 |
Correct |
149 ms |
14344 KB |
Output is correct |
9 |
Correct |
141 ms |
14220 KB |
Output is correct |
10 |
Correct |
146 ms |
14468 KB |
Output is correct |
11 |
Correct |
142 ms |
14480 KB |
Output is correct |
12 |
Correct |
164 ms |
13488 KB |
Output is correct |
13 |
Correct |
145 ms |
14092 KB |
Output is correct |
14 |
Correct |
139 ms |
14856 KB |
Output is correct |
15 |
Correct |
158 ms |
14420 KB |
Output is correct |
16 |
Correct |
3 ms |
4188 KB |
Output is correct |
17 |
Correct |
118 ms |
13588 KB |
Output is correct |
18 |
Correct |
143 ms |
13632 KB |
Output is correct |
19 |
Correct |
1 ms |
4188 KB |
Output is correct |
20 |
Correct |
1 ms |
4188 KB |
Output is correct |
21 |
Runtime error |
182 ms |
8528 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |