# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
383850 | JerryLiu06 | Secret (JOI14_secret) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include #include "secret.h"
using namespace std;
int dat[10][1010], mask[1010], A[1010];
void divide(int L, int R, int lev, int A[]) {
if (L == R) return ; int mid = (L + R) / 2;
dat[lev][mid] = mid; for (int i = mid - 1; i >= L; i--) dat[lev][i] = Secret(A[i], dat[lev][i + 1]);
dat[lev][mid + 1] = mid + 1; for (int i = mid + 2; i <= R; i++) dat[lev][i] = Secret(A[i], dat[lev][i - 1]);
for (int i = mid + 1; i <= R; i++) mask[i] ^= (1 << lev);
divide(L, mid, lev + 1, A); divide(mid + 1, R, lev + 1, A);
}
void Init(int N, int arr[]) { for (int i = 0; i < N; i++) A[i] = arr[i]; divide(1, N, 1, A); }
int Query(int L, int R) { if (L == R) return A[L];
int lev = __builtin_ctz(mask[L] ^ mask[R]); return Secret(dat[lev][L], dat[lev][R]);
}