#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int MAX = 1000;
int n;
int a[MAX];
int mask[MAX];
int dp[10][MAX];
void divi(int l, int r, int lev) {
if (l == r) return;
int mid = l + r >> 1;
dp[lev][mid] = a[mid]; dp[lev][mid + 1] = a[mid + 1];
for (int i = mid - 1; i >= l; --i) dp[lev][i] = Secret(dp[lev][i + 1], a[i]);
for (int i = mid + 2; i <= r; ++i) dp[lev][i] = Secret(dp[lev][i - 1], a[i]);
for (int i = mid + 1; i <= r; ++i) mask[i] = 1 << lev;
divi(l, mid, lev + 1); divi(mid + 1, r, lev + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; ++i) {
a[i] = A[i];
mask[i] = 0;
}
divi(0, n - 1, 0);
}
int Query(int L, int R) {
if (L == R) return a[L];
int lev = __builtin_ctz(mask[L], mask[R]);
return Secret(dp[lev][L], dp[lev][R]);
}
Compilation message
secret.cpp: In function 'void divi(int, int, int)':
secret.cpp:23:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | int mid = l + r >> 1;
| ~~^~~
secret.cpp: In function 'int Query(int, int)':
secret.cpp:42:45: error: too many arguments to function 'int __builtin_ctz(unsigned int)'
42 | int lev = __builtin_ctz(mask[L], mask[R]);
| ^