제출 #668969

#제출 시각아이디문제언어결과실행 시간메모리
668969boris_mihovAbracadabra (CEOI22_abracadabra)C++17
10 / 100
3053 ms26180 KiB
#include <unordered_map> #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <cstring> #include <vector> #include <cmath> #include <queue> typedef long long llong; const int MAXQ = 1000000 + 10; const int MAXN = 200000 + 10; const int INF = 1e9 + 1; struct Query { int idx; int pos; int time; inline friend bool operator < (const Query &a, const Query &b) { return a.time < b.time || (a.time == b.time && a.idx < b.idx); } }; int n, q; int a[MAXN]; int b[MAXN]; Query queries[MAXQ]; int ans[MAXQ]; void solve() { int qPtr = 1; bool areEqual = false; std::sort(queries + 1, queries + 1 + q); for (int shuffle = 0; !areEqual ; ++shuffle) { while (qPtr <= q && queries[qPtr].time == shuffle) { ans[queries[qPtr].idx] = a[queries[qPtr].pos]; qPtr++; } int lPtr = 1, rPtr = n/2 + 1, ptr = 1; while (lPtr <= n/2 || rPtr <= n) { if (lPtr == n/2 + 1) { b[ptr++] = a[rPtr++]; continue; } if (rPtr == n + 1) { b[ptr++] = a[lPtr++]; continue; } if (a[lPtr] < a[rPtr]) { b[ptr++] = a[lPtr++]; continue; } else { b[ptr++] = a[rPtr++]; continue; } } areEqual = true; for (int i = 1 ; i <= n ; ++i) { areEqual &= (a[i] == b[i]); a[i] = b[i]; } } while (qPtr <= q) { ans[queries[qPtr].idx] = a[queries[qPtr].pos]; qPtr++; } for (int i = 1 ; i <= q ; ++i) { std::cout << ans[i] << '\n'; } } void read() { std::cin >> n >> q; for (int i = 1 ; i <= n ; ++i) { std::cin >> a[i]; } for (int i = 1 ; i <= q ; ++i) { std::cin >> queries[i].time >> queries[i].pos; queries[i].idx = i; } } void fastIO() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIO(); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...