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;
const int MAXN = 2e5 + 500;
int n, q, t;
int niz[MAXN];
vector<int> v, novi;
vector<vector<int> > rj;
bool da = false;
int cnt;
void solve () {
for (int i = 0; i < n; i++) v.push_back (niz[i]);
for (int i = 0; i < n; i++) novi.push_back(niz[i]);
while (!da) {
v = novi;
novi.clear ();
int ind1 = 0, ind2 = n / 2;
while (ind1 < n / 2 || ind2 < n) {
if (ind1 == n / 2 || (ind2 < n && v[ind2] < v[ind1])) {
novi.push_back (v[ind2]);
ind2++;
}
else {
novi.push_back (v[ind1]);
ind1++;
}
}
da = true;
for (int i = 0; i < n; i++) {
if (v[i] != novi[i]) da = false;
}
rj.push_back(v);
cnt++;
}
// for (auto it: rj) {
// for (auto itt: it) cout << itt << ' ';
// cout << "\n";
// }
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie (0);
cout.tie (0);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> niz[i];
solve ();
for (int i = 0; i < q; i++) {
int t, a;
cin >> t >> a;
cout << rj[min (t, cnt - 1)][a - 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... |