# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1263927 | tminh | Secret (JOI14_secret) | C++20 | 0 ms | 0 KiB |
#include "secret.h"
#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1005 + 5;
const ll oo = 1e18;
bool START;
ll cur[N][10], a[N], n, bit[N];
void dnc(int l, int r, int depth) {
if (l == r) return;
int mid = (l + r) >> 1;
cur[mid][depth] = a[mid];
for (int i = mid - 1; i >= l; --i) cur[i][depth] = Secret(cur[i + 1][depth], a[i]);
cur[mid + 1][depth] = a[mid + 1];
for (int i = mid + 2; i <= r; ++i) cur[i][depth] = Secret(cur[i - 1][depth], a[i]);
for (int i = mid + 1; i <= r; ++i) bit[i] |= (1 << depth);
dnc(l, mid + 1, depth + 1);
dnc(mid + 1, r, depth + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 1; i <= n; ++i) a[i] = A[i - 1];
dnc(1, n, 0);
}
ll Query(int L, int R) {
++L; ++R;
int depth = __builtin_ctz(bit[L] ^ bit[R]);
ll ans = Secret(cur[L][depth], cur[R][depth]);
return ans;
}