# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
793470 | 2023-07-25T22:01:23 Z | asdfgrace | Secret (JOI14_secret) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; vector<vector<int>> lef, rig; void Init(int N, int A[]) { n = N; a.resize(N); for (int i = 0; i < N; ++i) a[i] = A[i]; lef.resize(N); rig.resize(N); queue<pair<int, int>> q; q.push({0, n - 1}); while (!q.empty()) { int l = q.front().first, r = q.front().second; q.pop(); int m = (l + r) / 2; lef[m].push_back(A[m]); for (int i = 1; i <= (m - l); ++i) { lef[m].push_back(Secret(A[m - i], lef[m].back())); } if (m + 1 < N) { rig[m].push_back(A[m + 1]); for (int i = 2; i <= (r - m); ++i) { rig[m].push_back(Secret(rig[m].back(), A[m + i])); } } if (l == r) continue; q.push({l, m}); q.push({m + 1, r}); } } int Query(int L, int R) { if (L == R) return a[L]; int l = 0, r = n - 1; while (true) { int m = (l + r) / 2; if (R <= m) { r = m; } else if (L > m) { l = m + 1; } else { return Secret(lef[m][m - L], rig[m][R - m - 1]); } } }