Submission #202635

#TimeUsernameProblemLanguageResultExecution timeMemory
202635maruiiSushi (JOI16_sushi)C++14
15 / 100
3199 ms86264 KiB
#include <bits/stdc++.h> using namespace std; const int B = 600; int A[400005]; priority_queue<int> q[700]; vector<int> stk[700]; int naive(int s, int e, int v) { if (s > e) return v; int a = (s - 1) / B; priority_queue<int, vector<int>, greater<int>> pq; for (auto i : stk[a]) pq.push(i); stk[a].clear(); for (int i = a * B + 1; i <= a * B + B; ++i) { pq.push(A[i]); A[i] = pq.top(); pq.pop(); } while (q[a].size()) q[a].pop(); for (int i = s; i <= e; ++i) { if (v < A[i]) swap(v, A[i]); q[a].push(A[i]); } return v; } int query(int s, int e, int v) { int a = (s - 1) / B + 1; int b = (e - 1) / B; if (b < a) return naive(s, e, v); v = naive(s, a * B, v); for (int i = a; i < b; ++i) { stk[i].push_back(v); q[i].push(v); v = q[i].top(); q[i].pop(); } v = naive(b * B + 1, e, v); return v; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int N, Q; cin >> N >> Q; for (int i = 1; i <= N; ++i) { cin >> A[i]; q[(i - 1) / B].push(A[i]); } while (Q--) { int s, t, p; cin >> s >> t >> p; int res; if (s <= t) res = query(s, t, p); else res = query(1, t, query(s, N, p)); printf("%d\n", res); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...