이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n, q;
cin >> n >> q;
vector<int> a(n), b(n);
for (int &i : a) cin >> i;
vector<array<int, 3>> que(q);
for (int i = 0; i < q; ++i) {
cin >> que[i][0] >> que[i][1];
que[i][2] = i;
}
sort(que.begin(), que.end());
vector<int> ans(q);
int j = 0;
for (int i = 0; true; ++i) {
while (j < q && que[j][0] == i) {
ans[que[j][2]] = a[que[j][1]-1];
++j;
}
int x = 0, y = 0, z = n/2;
while (y < n/2 && z < n) {
if (a[y] < a[z]) b[x++] = a[y++];
else b[x++] = a[z++];
}
while (y < n/2) b[x++] = a[y++];
while (z < n) b[x++] = a[z++];
if (a == b) break;
a = b;
}
while (j < q) {
ans[que[j][2]] = a[que[j][1]-1];
++j;
}
for (int i = 0; i < q; ++i) cout << ans[i] << '\n';
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |