# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
647806 | clams | Secret (JOI14_secret) | C++17 | 455 ms | 4452 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 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |