Submission #538902

#TimeUsernameProblemLanguageResultExecution timeMemory
538902schiftyfive4Secret (JOI14_secret)C++14
100 / 100
451 ms4448 KiB
#include <bits/stdc++.h> #include "secret.h" using namespace std; int n; vector<vector<int>> t(15, vector<int>(1005)); void calc(int L, int R, int dep, int A[]) { assert(dep < 15); if (L == R) { t[dep][L] = A[L]; return; } int m = (L + R) / 2; t[dep][m] = A[m]; for (int i = m - 1; i >= L; i--) { t[dep][i] = Secret(A[i], t[dep][i + 1]); } t[dep][m + 1] = A[m + 1]; for (int i = m + 2; i <= R; i++) { t[dep][i] = Secret(t[dep][i - 1], A[i]); } calc(L, m, dep + 1, A); calc(m + 1, R, dep + 1, A); } void Init(int N, int A[]) { n = N; calc(0, n - 1, 0, A); } int get(int L, int R, int qL, int qR, int dep) { assert(dep < 15); assert(L <= qL && qR <= R); if (L == R) { return t[dep][L]; } int m = (L + R) / 2; if (qL <= m && m + 1 <= qR) { return Secret(t[dep][qL], t[dep][qR]); } else if (qR <= m) { return get(L, m, qL, qR, dep + 1); } return get(m + 1, R, qL, qR, dep + 1); } int Query(int L, int R) { return get(0, n - 1, L, R, 0); }
#Verdict Execution timeMemoryGrader output
Fetching results...