# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1014124 | atom | Abracadabra (CEOI22_abracadabra) | C++17 | 149 ms | 18256 KiB |
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"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
const int N = 1e5 + 5;
vector <int> ans[N];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#ifdef JASPER
freopen("in1", "r", stdin);
#endif
int n, q;
cin >> n >> q;
vector <int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
if (n <= 1000) {
int m = n / 2;
ans[0] = a;
for (int t = 1; t <= n; ++t) {
queue <int> l, r;
vector <int> b;
for (int i = 0; i < m; ++i) l.push(a[i]);
for (int i = m; i < n; ++i) r.push(a[i]);
while (!l.empty() || !r.empty()) {
if (!l.empty() && !r.empty() && l.front() < r.front()) {
b.push_back(l.front());
l.pop();
}
if (!l.empty() && !r.empty() && l.front() > r.front()) {
b.push_back(r.front());
r.pop();
}
if (l.empty()) {
while (!r.empty()) {
b.push_back(r.front());
r.pop();
}
}
if (r.empty()) {
while (!l.empty()) {
b.push_back(l.front());
l.pop();
}
}
}
debug(b);
ans[t] = b;
a = b;
}
while (q--) {
int x, i;
cin >> x >> i;
x = min(x, n);
cout << ans[x][i - 1] << "\n";
}
}
return 0;
}
Compilation message (stderr)
# | 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... |