#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;
const int lg = 10;
int *a;
vector<int> st[lg];
vector<int> mask;
void Init(int N, int A[]) {
a = A;
for (int i = 0; i < lg; ++i) {
st[i].resize(N);
}
mask.resize(N);
auto calc = [&](auto calc, int l, int r, int k) -> void {
if (l == r) {
return;
}
int mid = (l + r) / 2;
st[k][mid] = A[mid];
for (int i = mid - 1; i >= l; --i) {
st[k][i] = Secret(A[i], st[k][i + 1]);
}
st[k][mid + 1] = A[mid + 1];
for (int i = mid + 2; i <= r; ++i) {
st[k][i] = Secret(st[k][i - 1], A[i]);
}
for (int i = mid + 1; i <= r; ++i) {
mask[i] ^= (1 << k);
}
calc(calc, l, mid, k + 1);
calc(calc, mid + 1, r, k + 1);
};
calc(calc, 0, N - 1, 0);
}
int Query(int L, int R) {
if (L == R) {
return a[L];
}
int k = __builtin_ctz(mask[L] ^ mask[R]);
return Secret(st[k][L], st[k][R]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
2548 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
86 ms |
2492 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
86 ms |
2368 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
309 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
308 ms |
4384 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
308 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
325 ms |
4472 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
308 ms |
4316 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
315 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
312 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |