Submission #861197

#TimeUsernameProblemLanguageResultExecution timeMemory
861197vgtcrossAbracadabra (CEOI22_abracadabra)C++17
10 / 100
3017 ms27216 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; void solve() { int n, q; cin >> n >> q; vector<int> a(n), b(n); for (int &i : a) cin >> i; vector<array<int, 3>> que(q); for (int i = 0; i < q; ++i) { cin >> que[i][0] >> que[i][1]; que[i][2] = i; } sort(que.begin(), que.end()); vector<int> ans(q); int j = 0; for (int i = 0; true; ++i) { while (j < q && que[j][0] == i) { ans[que[j][2]] = a[que[j][1]-1]; ++j; } int x = 0, y = 0, z = n/2; while (y < n/2 && z < n) { if (a[y] < a[z]) b[x++] = a[y++]; else b[x++] = a[z++]; } while (y < n/2) b[x++] = a[y++]; while (z < n) b[x++] = a[z++]; if (a == b) break; a = b; } while (j < q) { ans[que[j][2]] = a[que[j][1]-1]; ++j; } for (int i = 0; i < q; ++i) cout << ans[i] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...