#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
#define ll long long
#define lc (node<<1)+1
#define rc (node<<1)+2
#define endl '\n'
#define INF 1e9
const int max_n = 1000;
const int max_log = (int)log2(max_n) + 2;
int dat[max_log][max_n];
int arr[max_n], mask[max_n];
void divi(int left, int right, int level){
if(left == right) return;
int mid = (left + right) / 2;
dat[level][mid] = arr[mid];
for(int i = mid-1; i >= left; i --){
dat[level][i] = Secret(arr[i], dat[level][i+1]);
}
dat[level][mid+1] = arr[mid+1];
for(int i = mid+2; i <= right; i ++){
dat[level][i] = Secret(dat[level][i-1], arr[i]);
}
for(int i = mid+1; i <= right; i ++){
mask[i] ^= (1 << level);
}
divi(left, mid, level+1); divi(mid+1, right, level + 1);
}
void Init(int N, int A[]){
for(int i = 0; i < N; i ++){
arr[i] = A[i];
}
divi(0, N-1, 0);
}
int Query(int L, int R){
if(L == R) return arr[L];
int bits = __builtin_ctz(mask[L] ^ mask[R]);
return Secret(dat[bits][L], dat[bits][R]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
2372 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
119 ms |
2348 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
126 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 |
441 ms |
4224 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
446 ms |
4280 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
425 ms |
4320 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
433 ms |
4316 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
452 ms |
4292 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
450 ms |
4324 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
430 ms |
4440 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |