Submission #647806

#TimeUsernameProblemLanguageResultExecution timeMemory
647806clamsSecret (JOI14_secret)C++17
100 / 100
455 ms4452 KiB
#include "secret.h" #include <bits/stdc++.h> using namespace std; const int N = 1e3 + 5; const int LG = __lg(N) + 1; const int LIM = 8000; int n; int a[N]; int dat[LG][N]; int msk[N]; void Rec(int l, int r, int lvl) { if (l == r) return; int m = (l + r) / 2; dat[lvl][m] = a[m]; for (int i = m - 1; i >= l; i--) { dat[lvl][i] = Secret(a[i], dat[lvl][i + 1]); // notice the order } dat[lvl][m + 1] = a[m + 1]; for (int i = m + 2; i <= r; i++) { dat[lvl][i] = Secret(dat[lvl][i - 1], a[i]); } for (int i = m + 1; i <= r; i++) { msk[i] |= (1 << lvl); } Rec(l, m, lvl + 1); Rec(m + 1, r, lvl + 1); } int Query(int l, int r) { if (l == r) return a[l]; int lvl = __builtin_ctz(msk[l] ^ msk[r]); return Secret(dat[lvl][l], dat[lvl][r]); } void Init(int sz, int A[]) { copy(A, A + sz, a); n = sz; Rec(0, n - 1, 0); }
#Verdict Execution timeMemoryGrader output
Fetching results...