# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798115 | IvanJ | Abracadabra (CEOI22_abracadabra) | C++17 | 3051 ms | 31348 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 pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 2e5 + 5, maxq = 1e6 + 5;
int n, q;
int p[maxn];
int ans[maxq];
vector<ii> qs[maxn];
vector<int> get(vector<int> L, vector<int> R) {
int i = 0, j = 0;
vector<int> ret;
while(i < (n / 2) || j < (n / 2)) {
if(i == n / 2) ret.pb(R[j++]);
else if(j == n / 2) ret.pb(L[i++]);
else {
if(L[i] < R[j])
ret.pb(L[i++]);
else ret.pb(R[j++]);
}
}
return ret;
}
int main() {
scanf("%d%d", &n, &q);
for(int i = 0;i < n;i++)
scanf("%d", p + i);
for(int i = 0;i < q;i++) {
int t, x;
scanf("%d%d", &t, &x);
x--;
qs[min(t, n)].pb({x, i});
}
for(int t = 0;t <= n;t++) {
for(ii qi : qs[t])
ans[qi.y] = p[qi.x];
vector<int> L, R;
for(int i = 0;i < n / 2;i++) L.pb(p[i]);
for(int i = n / 2;i < n;i++) R.pb(p[i]);
vector<int> v = get(L, R);
for(int i = 0;i < n;i++) p[i] = v[i];
}
for(int i = 0;i < q;i++)
printf("%d\n", ans[i]);
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... |