#include <bits/stdc++.h>
#include "secret.h"
using namespace std;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,true:false; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,true:false; }
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rng() {
return abs((int)mrand());
}
// Current challenge: finish CSES problemset!!
constexpr int nax = 1000, lg = 10;
int cnt;
int res[lg][nax];
int mask[nax];
int a[nax];
/*
int Secret(int x,int y) {
cnt++;
return x+y;
}
*/
void build(int l,int r,int pw) {
if (l == r) {
return;
}
int m = (l+r)/2;
res[pw][m] = a[m];
for (int i=m-1;i>=l;i--) { res[pw][i] = Secret(res[pw][i+1],a[i]); }
res[pw][m+1] = a[m+1];
for (int i=m+2;i<=r;i++) { res[pw][i] = Secret(res[pw][i-1],a[i]); }
for (int i=m+1;i<=r;i++) { mask[i] ^= 1 << pw; }
build(l,m,pw+1);
build(m+1,r,pw+1);
}
void Init(int n,int _a[]) {
for (int i=0;i<n;i++) {
a[i] = _a[i];
}
build(0,n-1,0);
}
int Query(int l,int r) {
if (l == r) { return a[l]; }
int bits = __builtin_ctz(mask[l] ^ mask[r]);
return Secret(res[bits][l],res[bits][r]);
}
/*
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int _a[n];
for (int i=0;i<n;i++) {
cin >> _a[i];
}
Init(n,_a);
cout << cnt << endl;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
71 ms |
2460 KB |
Wrong Answer: Query(222, 254) - expected : 34031541, actual : 268854015. |
2 |
Incorrect |
72 ms |
2412 KB |
Wrong Answer: Query(60, 375) - expected : 669221184, actual : 311474560. |
3 |
Incorrect |
75 ms |
2520 KB |
Wrong Answer: Query(211, 401) - expected : 674373968, actual : 353554500. |
4 |
Incorrect |
298 ms |
4368 KB |
Wrong Answer: Query(90, 497) - expected : 397934825, actual : 343081568. |
5 |
Incorrect |
268 ms |
4316 KB |
Wrong Answer: Query(587, 915) - expected : 752404486, actual : 957013316. |
6 |
Incorrect |
275 ms |
4588 KB |
Wrong Answer: Query(200, 208) - expected : 277813445, actual : 154975445. |
7 |
Incorrect |
289 ms |
4436 KB |
Wrong Answer: Query(84, 976) - expected : 742463504, actual : 675449873. |
8 |
Incorrect |
274 ms |
4432 KB |
Wrong Answer: Query(58, 987) - expected : 20022464, actual : 273091792. |
9 |
Incorrect |
276 ms |
4296 KB |
Wrong Answer: Query(33, 967) - expected : 676869696, actual : 827853577. |
10 |
Incorrect |
297 ms |
4380 KB |
Wrong Answer: Query(116, 961) - expected : 68487362, actual : 337854787. |