#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
const int MAX_N = 1005;
int n, a[MAX_N], dat[MAX_N][15], mask[MAX_N];
void divi(int l, int r, int lev) {
if (l == r) return;
int m = (l + r) / 2;
dat[m][lev] = a[m];
for (int i = m - 1; i >= l; i--) {
dat[i][lev] = Secret(a[i], dat[i + 1][lev]);
}
dat[m + 1][lev] = a[m + 1];
for (int i = m + 2; i <= r; i++) {
dat[i][lev] = Secret(dat[i - 1][lev], a[i]);
}
for (int i = m + 1; i <= r; i++) {
mask[i] ^= (1 << lev);
}
divi(l, m, lev + 1);
divi(m + 1, r, lev + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < N; i++) {
a[i] = A[i];
}
divi(0, n - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
int bits = __builtin_ctz(mask[L] ^ mask[R]);
return Secret(dat[L][bits], dat[R][bits]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
145 ms |
2328 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
144 ms |
2324 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
153 ms |
2400 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
512 ms |
4336 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
518 ms |
4256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
507 ms |
4296 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
519 ms |
4256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
527 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
530 ms |
4304 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
520 ms |
4284 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |