#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
a[i]--;
}
std::vector<std::vector<std::pair<int, int>>> Q(n + 1);
std::vector<int> ans(q);
for (int i = 0; i < q; i++) {
int t, p;
std::cin >> t >> p;
t = std::min(t, n);
p--;
Q[t].push_back({p, i});
}
for (int t = 0; t <= n; t++) {
for (auto [p, id] : Q[t]) {
ans[id] = a[p];
}
int l = 0, r = n / 2;
std::vector<int> na;
while (l < n / 2 && r < n) {
if (a[l] < a[r]) {
na.push_back(a[l++]);
} else {
na.push_back(a[r++]);
}
}
while (l < n / 2) {
na.push_back(a[l++]);
}
while (r < n) {
na.push_back(a[r++]);
}
a = na;
}
for (int i = 0; i < q; i++) {
std::cout << ans[i] + 1 << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
26036 KB |
Output is correct |
2 |
Correct |
210 ms |
24524 KB |
Output is correct |
3 |
Correct |
198 ms |
24004 KB |
Output is correct |
4 |
Correct |
233 ms |
22516 KB |
Output is correct |
5 |
Correct |
205 ms |
25992 KB |
Output is correct |
6 |
Correct |
194 ms |
25880 KB |
Output is correct |
7 |
Correct |
217 ms |
27208 KB |
Output is correct |
8 |
Correct |
191 ms |
24464 KB |
Output is correct |
9 |
Correct |
220 ms |
23692 KB |
Output is correct |
10 |
Correct |
195 ms |
23356 KB |
Output is correct |
11 |
Correct |
221 ms |
23716 KB |
Output is correct |
12 |
Correct |
182 ms |
20884 KB |
Output is correct |
13 |
Correct |
192 ms |
22340 KB |
Output is correct |
14 |
Correct |
229 ms |
25504 KB |
Output is correct |
15 |
Correct |
209 ms |
23084 KB |
Output is correct |
16 |
Correct |
3 ms |
320 KB |
Output is correct |
17 |
Correct |
189 ms |
21128 KB |
Output is correct |
18 |
Correct |
195 ms |
21076 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
33756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
8644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
26036 KB |
Output is correct |
2 |
Correct |
210 ms |
24524 KB |
Output is correct |
3 |
Correct |
198 ms |
24004 KB |
Output is correct |
4 |
Correct |
233 ms |
22516 KB |
Output is correct |
5 |
Correct |
205 ms |
25992 KB |
Output is correct |
6 |
Correct |
194 ms |
25880 KB |
Output is correct |
7 |
Correct |
217 ms |
27208 KB |
Output is correct |
8 |
Correct |
191 ms |
24464 KB |
Output is correct |
9 |
Correct |
220 ms |
23692 KB |
Output is correct |
10 |
Correct |
195 ms |
23356 KB |
Output is correct |
11 |
Correct |
221 ms |
23716 KB |
Output is correct |
12 |
Correct |
182 ms |
20884 KB |
Output is correct |
13 |
Correct |
192 ms |
22340 KB |
Output is correct |
14 |
Correct |
229 ms |
25504 KB |
Output is correct |
15 |
Correct |
209 ms |
23084 KB |
Output is correct |
16 |
Correct |
3 ms |
320 KB |
Output is correct |
17 |
Correct |
189 ms |
21128 KB |
Output is correct |
18 |
Correct |
195 ms |
21076 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Execution timed out |
3055 ms |
33756 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |