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;
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
int n, q;
int x, y;
vector <int> v;
vector <int> sol[1000];
vector <int> f() {
vector <int> ret;
int a = 0;
int b = n / 2;
while (a < n / 2 || b < n) {
if (a == n / 2) {
ret.push_back(v[b]);
b++;
}
else if (b == n) {
ret.push_back(v[a]);
a++;
}
else {
if (v[a] < v[b]) {
ret.push_back(v[a]);
a++;
}
else {
ret.push_back(v[b]);
b++;
}
}
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
srand(time(0));
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
// for (int i = 1; i <= n; i++) v.push_back(i);
// random_shuffle(v.begin(), v.end());
int cnt = 0;
sol[0] = v;
while (true) {
if (v == f()) break;
v = f();
cnt++;
sol[cnt] = v;
}
while (q--) {
cin >> x >> y;
if (x > cnt) cout << sol[cnt][y - 1] << "\n";
else cout << sol[x][y - 1] << "\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... |