# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784421 | chanhchuong123 | Secret (JOI14_secret) | C++14 | 418 ms | 4504 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 "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200200;
int n;
int a[MAX];
int mask[MAX];
int dp[18][MAX];
void divide(int l, int r, int level) {
if (l == r) return;
int mid = l + r >> 1;
dp[level][mid] = a[mid]; dp[level][mid + 1] = a[mid + 1];
for (int i = mid - 1; i >= l; --i) dp[level][i] = Secret(a[i], dp[level][i + 1]);
for (int i = mid + 2; i <= r; ++i) dp[level][i] = Secret(dp[level][i - 1], a[i]);
for (int i = mid + 1; i <= r; ++i) mask[i] ^= 1 << level;
divide(l, mid, level + 1); divide(mid + 1, r, level + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; ++i) {
a[i] = A[i];
mask[i] = 0;
}
divide(0, n - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
int lev = __builtin_ctz(mask[L] ^ mask[R]);
return Secret(dp[lev][L], dp[lev][R]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |