Submission #698044

#TimeUsernameProblemLanguageResultExecution timeMemory
698044badontSecret (JOI14_secret)C++17
0 / 100
20051 ms4756 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; struct Tree { vector<vector<int>> left, right; int n; void init(int n, const vector<int>& data) { this->n = n; left.resize(4 * n + 5); right.resize(4 * n + 5); auto dfs = [&](auto dfs, int z, int l, int r) -> void { int m = (l + r) >> 1; left[z].resize(m - l + 1); right[z].resize(r - m); if (l == r) { left[z][0] = data[l]; return; } left[z][0] = data[m]; for (int i = m - 1, idx = 1; i >= l; i--, idx++) { left[z][idx] = Secret(left[z][idx - 1], data[i]); } right[z][0] = data[m + 1]; for (int i = m + 2, idx = 1; i <= r; i++, idx++) { right[z][idx] = Secret(right[z][idx - 1], data[i]); } dfs(dfs, 2 * z, l, m); dfs(dfs, 2 * z + 1, m + 1, r); }; dfs(dfs, 1, 0, n - 1); } int query(int z, int l, int r, int ql, int qr) { int m = (l + r) >> 1; if (qr <= m) return query(2 * z, l, m, ql, qr); if (ql >= m + 1) return query(2 * z + 1, m + 1, r, ql, qr); int idx1 = m - ql, idx2 = qr - (m + 1); if (ql == qr) return left[z][idx1]; return Secret(left[z][idx1], right[z][idx2]); } int query(int ql, int qr) { return query(1, 0, n - 1, ql, qr); } } tree; void Init(int N, int A[]) { vector<int> a(N); for (int i = 0; i < N; i++) a[i] = A[i]; tree.init(N, a); } int Query(int L, int R) { return tree.query(L, R); }
#Verdict Execution timeMemoryGrader output
Fetching results...