# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
971599 | nguyentunglam | Abracadabra (CEOI22_abracadabra) | C++17 | 3050 ms | 28032 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>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int N = 1e5 + 10;
int n, q;
int a[N], b[N], c[N], ans[N];
vector<pair<int, int> > query[N];
int32_t main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
if (fopen(task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= q; i++) {
int t, x; cin >> t >> x;
query[min(n, t)].emplace_back(x, i);
}
b[n / 2 + 1] = c[n / 2 + 1] = 1e9;
for(int turn = 0; turn <= n; turn++) {
// for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
for(auto &[x, i] : query[turn]) {
ans[i] = a[x];
}
for(int i = 1; i <= n / 2; i++) b[i] = a[i];
for(int i = n / 2 + 1; i <= n; i++) c[i - n / 2] = a[i];
// for(int i = 1; i <= n / 2; i++) cout << b[i] << " "; cout << endl;
// for(int i = 1; i <= n / 2; i++) cout << c[i] << " "; cout << endl;
for(int i = 1, j = 1; i <= n / 2 || j <= n / 2; ) {
if (b[i] < c[j]) a[i + j - 1] = b[i], i++;
else a[i + j - 1] = c[j], j++;
}
// for(int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
}
for(int i = 1; i <= q; i++) cout << ans[i] << endl;
}
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... |