#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1007;
int n, q, a[N];
vector<int> g[N];
signed main () {
ios_base::sync_with_stdio(NULL);
cin.tie(0), cout.tie(0);
cin >> n >> q;
int lol = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
g[lol].push_back(a[i]);
}
while (lol <= 1000) {
lol++;
int l = 0, r = n/2;
while (l < n/2 || r < n) {
if (l == n/2) {
g[lol].push_back(g[lol-1][r]);
r++;
continue;
}
if (r == n) {
g[lol].push_back(g[lol-1][l]);
l++;
continue;
}
if (g[lol-1][l] <= g[lol-1][r]) {
g[lol].push_back(g[lol-1][l]);
l++;
} else {
g[lol].push_back(g[lol-1][r]);
r++;
}
}
if (g[lol] == g[lol-1]) break;
}
while (q--) {
int i, j;
cin >> i >> j;
cout << g[min(lol, i)][j-1] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
12288 KB |
Output is correct |
2 |
Correct |
210 ms |
6276 KB |
Output is correct |
3 |
Correct |
187 ms |
7884 KB |
Output is correct |
4 |
Correct |
207 ms |
4232 KB |
Output is correct |
5 |
Correct |
206 ms |
5536 KB |
Output is correct |
6 |
Correct |
209 ms |
4876 KB |
Output is correct |
7 |
Correct |
195 ms |
5804 KB |
Output is correct |
8 |
Correct |
185 ms |
4684 KB |
Output is correct |
9 |
Correct |
173 ms |
4456 KB |
Output is correct |
10 |
Correct |
178 ms |
4560 KB |
Output is correct |
11 |
Correct |
167 ms |
4556 KB |
Output is correct |
12 |
Correct |
165 ms |
4104 KB |
Output is correct |
13 |
Correct |
174 ms |
4228 KB |
Output is correct |
14 |
Correct |
217 ms |
5064 KB |
Output is correct |
15 |
Correct |
206 ms |
4340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
212 ms |
4056 KB |
Output is correct |
18 |
Correct |
170 ms |
4076 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
12288 KB |
Output is correct |
2 |
Correct |
210 ms |
6276 KB |
Output is correct |
3 |
Correct |
187 ms |
7884 KB |
Output is correct |
4 |
Correct |
207 ms |
4232 KB |
Output is correct |
5 |
Correct |
206 ms |
5536 KB |
Output is correct |
6 |
Correct |
209 ms |
4876 KB |
Output is correct |
7 |
Correct |
195 ms |
5804 KB |
Output is correct |
8 |
Correct |
185 ms |
4684 KB |
Output is correct |
9 |
Correct |
173 ms |
4456 KB |
Output is correct |
10 |
Correct |
178 ms |
4560 KB |
Output is correct |
11 |
Correct |
167 ms |
4556 KB |
Output is correct |
12 |
Correct |
165 ms |
4104 KB |
Output is correct |
13 |
Correct |
174 ms |
4228 KB |
Output is correct |
14 |
Correct |
217 ms |
5064 KB |
Output is correct |
15 |
Correct |
206 ms |
4340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
212 ms |
4056 KB |
Output is correct |
18 |
Correct |
170 ms |
4076 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |