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>
using namespace std;
int dd[1002][1001];
int n, q;
int main () {
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> dd[0][i];
for (int i = 1; i <= n; i++) {
deque <int> a, b;
for (int j = 1; j <= n / 2; j++) a.push_back(dd[i - 1][j]);
for (int j = n / 2 + 1; j <= n; j++) b.push_back(dd[i - 1][j]);
int c = 0;
while (!a.empty() && !b.empty()) {
if (a.front() < b.front()) {
dd[i][++c] = a.front(); a.pop_front();
} else {
dd[i][++c] = b.front(); b.pop_front();
}
}
while (!a.empty()) dd[i][++c] = a.front(), a.pop_front();
while (!b.empty()) dd[i][++c] = b.front(), b.pop_front();
}
while (q--) {
int x, y; cin >> x >> y;
x = min(x, n);
cout << dd[x][y] << '\n';
}
}
# | 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... |