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 pb push_back
#define nl "\n"
using namespace std;
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
int n, q, a[N];
int b[1001][1001];
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> n >> q;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
b[0][i] = a[i];
}
for(int x = 1; x <= n; ++x) {
vector<int> l, r, v;
for(int i = 1; i <= n / 2; ++i) l.pb(b[x - 1][i]);
for(int i = n / 2 + 1; i <= n; ++i) r.pb(b[x - 1][i]);
int i1 = 0, i2 = 0;
for(int i = 1; i <= n; ++i) {
if(i1 < n / 2 && i2 < n / 2) {
if(l[i1] < r[i2]) v.pb(l[i1++]);
else v.pb(r[i2++]);
}
if(i1 == n / 2) {
v.pb(r[i2++]);
continue;
}
if(i2 == n / 2) {
v.pb(l[i1++]);
continue;
}
}
for(int i = 1; i <= n; ++i) b[x][i] = v[i - 1];
}
while(q--) {
int i, x;
cin >> x >> i;
cout << b[min(n, x)][i] << nl;
}
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... |