#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 res[lg][nax];
int mask[nax];
int a[nax];
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(a[i],res[pw][i+1]); }
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]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
2648 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
93 ms |
2648 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
77 ms |
2824 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
297 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
318 ms |
4360 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
306 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
309 ms |
4352 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
286 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
292 ms |
4336 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
307 ms |
4352 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |