#include "secret.h"
#include <bits/stdc++.h>
const int MX = 1001;
int tab[13][MX];
int mask[MX];
int n, a[MX];
void prepare(int l, int r, int level) {
if(l==r) return;
int m = (l+r)/2;
tab[level][m] = a[m];
tab[level][m+1] = a[m+1];
for(int i=m-1; i>=l; --i) {
tab[level][i] = Secret(a[i], tab[level][i+1]);
}
mask[m+1] ^= 1<<level;
for(int i=m+2; i<=r; ++i) {
tab[level][i] = Secret(tab[level][i-1], a[i]);
mask[i] ^= 1<<level;
}
prepare(l, m, level+1);
prepare(m+1, r, level+1);
}
void Init(int N, int A[]) {
n = N;
for(int i=0; i<n; ++i) {
a[i] = A[i];
}
prepare(0, n-1, 0);
}
int Query(int L, int R) {
if(L==R) return a[L];
int level = __builtin_ctz(mask[L]^mask[R]);
return Secret(tab[level][L], tab[level][R]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
2340 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
126 ms |
2340 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
131 ms |
2436 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
438 ms |
4276 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
470 ms |
4312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
447 ms |
4268 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
478 ms |
4296 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
442 ms |
4324 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
454 ms |
4332 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
454 ms |
4212 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |