#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;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
102 ms |
4680 KB |
Execution killed with signal 11 |
2 |
Incorrect |
102 ms |
2432 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 436403617. |
3 |
Incorrect |
101 ms |
2380 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 497206465. |
4 |
Incorrect |
375 ms |
4412 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 113654935. |
5 |
Runtime error |
394 ms |
8632 KB |
Execution killed with signal 11 |
6 |
Incorrect |
379 ms |
4344 KB |
Wrong Answer: Query(738, 741) - expected : 983692994, actual : 998937626. |
7 |
Runtime error |
377 ms |
8616 KB |
Execution killed with signal 11 |
8 |
Runtime error |
379 ms |
8584 KB |
Execution killed with signal 11 |
9 |
Runtime error |
384 ms |
8596 KB |
Execution killed with signal 11 |
10 |
Incorrect |
398 ms |
4324 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 346751192. |