Submission #714472

#TimeUsernameProblemLanguageResultExecution timeMemory
714472MattTheNubSecret (JOI14_secret)C++17
0 / 100
459 ms4532 KiB
#include "secret.h" int *a; int dat[18][1005]{0}; int mask[1005]{0}; void compute(int l, int r, int depth) { if (l == r) return; int mid = (l + r) / 2; dat[depth][mid] = a[mid]; for (int i = mid - 1; i >= l; i--) dat[depth][i] = Secret(a[i], dat[depth][i + 1]); dat[depth][mid + 1] = a[mid + 1]; for (int i = mid + 2; i <= r; i++) dat[depth][i] = Secret(a[i], dat[depth][i - 1]); for (int i = mid + 1; i <= r; i++) { mask[i] ^= 1 << depth; } compute(l, mid, depth + 1); compute(mid + 1, r, depth + 1); } void Init(int N, int A[]) { a = A; compute(0, N - 1, 0); } int Query(int L, int R) { if (L == R) return a[L]; int x = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dat[x][L], dat[x][R]); }
#Verdict Execution timeMemoryGrader output
Fetching results...