#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1024;
int n;
int a[MAX];
int mask[MAX];
int dp[15][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:13:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
105 ms |
4684 KB |
Execution killed with signal 11 |
2 |
Incorrect |
104 ms |
2312 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 436403617. |
3 |
Incorrect |
102 ms |
2416 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 497206465. |
4 |
Incorrect |
382 ms |
4260 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 113654935. |
5 |
Runtime error |
404 ms |
8568 KB |
Execution killed with signal 11 |
6 |
Incorrect |
376 ms |
4304 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 998937626. |
7 |
Runtime error |
378 ms |
8592 KB |
Execution killed with signal 11 |
8 |
Runtime error |
382 ms |
8532 KB |
Execution killed with signal 11 |
9 |
Runtime error |
381 ms |
8548 KB |
Execution killed with signal 11 |
10 |
Incorrect |
377 ms |
4288 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 346751192. |