#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200200;
int n;
int a[MAX];
int mask[MAX];
int dp[18][MAX];
void divide(int l, int r, int level) {
if (l == r) return;
int mid = l + r >> 1;
dp[level][mid] = a[mid]; dp[level][mid + 1] = a[mid + 1];
for (int i = mid - 1; i >= l; --i) dp[level][i] = Secret(a[i], dp[level][i + 1]);
for (int i = mid + 2; i <= r; ++i) dp[level][i] = Secret(dp[level][i - 1], a[i]);
for (int i = mid + 1; i <= r; ++i) mask[i] ^= 1 << level;
divide(l, mid, level + 1); divide(mid + 1, r, level + 1);
}
void Init(int N, int A[]) {
n = N;
for (int i = 0; i < n; ++i) {
a[i] = A[i];
mask[i] = 0;
}
divide(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 divide(int, int, int)':
secret.cpp:13:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
2336 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
110 ms |
2444 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
109 ms |
2372 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
385 ms |
4384 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
381 ms |
4372 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
390 ms |
4504 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
399 ms |
4300 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
418 ms |
4504 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
383 ms |
4356 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
407 ms |
4416 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |