This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
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... |