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 n;
vector<int> shf(vector<int> v) {
vector<int> ans;
int m = n/2;
int p1 = 0, p2 = m;
while ((p1 < m) || (p2 < n)) {
if (p1 == m) {
ans.push_back(v[p2]);
p2++;
continue;
}
if (p2 == n) {
ans.push_back(v[p1]);
p1++;
continue;
}
if (v[p1] < v[p2]) {
ans.push_back(v[p1]);
p1++;
} else {
ans.push_back(v[p2]);
p2++;
}
}
return ans;
}
#define pii pair<int, int>
#define fr first
#define se second
int32_t main() {
int q;
cin >> n >> q;
vector<int> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
vector<pair<pii, int>> queries(q);
vector<int> ans(q);
for (int i = 0; i < q; i++) {
cin >> queries[i].fr.fr >> queries[i].fr.se;
queries[i].se = i;
}
sort(queries.begin(), queries.end());
int t = 0;
bool done = 0;
for (auto u : queries) {
while ((u.fr.fr > t) && !done) {
vector<int> novo = shf(s);
if (novo == s) {
done = 1;
} else {
s = novo;
}
t++;
}
ans[u.se] = s[u.fr.se - 1];
}
for (auto u : ans) cout << u << "\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... |