#include "secret.h"
int n, pref[1000][1000];
void precompute(int l, int r, int A[]) {
int mid = l + r >> 1;
pref[mid][mid] = A[mid];
pref[mid+1][mid+1] = A[mid+1];
for (int i = mid - 1; i >= l; i--) {
pref[mid][i] = Secret(pref[mid][i+1], A[i]);
}
for (int i = mid + 2; i <= r; i++) {
pref[mid+1][i] = Secret(pref[mid+1][i-1], A[i]);
}
if (l < mid) {
precompute(l, mid, A);
}
if (mid + 1 < r) {
precompute(mid + 1, r, A);
}
}
void Init(int N, int A[]) {
n = N;
precompute(0, N - 1, A);
}
int Query(int L, int R) {
int lo = 0, hi = N - 1;
while (lo != hi) {
int mid = lo + hi >> 1;
if (L <= mid && mid < R) {
return Secret(pref[mid][L], pref[mid+1][R]);
}
if (R == mid) {
return pref[mid][L];
}
if (mid < L) {
lo = mid + 1;
} else {
hi = mid;
}
}
return pref[lo][lo];
}
Compilation message
secret.cpp: In function 'void precompute(int, int, int*)':
secret.cpp:4:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
4 | int mid = l + r >> 1;
| ~~^~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:25:19: error: 'N' was not declared in this scope
25 | int lo = 0, hi = N - 1;
| ^
secret.cpp:27:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int mid = lo + hi >> 1;
| ~~~^~~~