#include "secret.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define cst(T) const T&
template<class A, class B> bool umin(A& var, cst(B) val) {
return (val < var) ? (var = val, true) : false;
}
template<class A, class B> bool umax(A& var, cst(B) val) {
return (var < val) ? (var = val, true) : false;
}
typedef long long Int;
typedef long double Real;
const int MOD = 2004010501;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class X, class Y> Int random(const X& l, const Y& r) {
return uniform_int_distribution<Int>(l,r)(rng);
}
#define DBG(x) cerr << #x << " = " << x << ' ';
#define DBGn(x) cerr << #x << " = " << x << '\n';
const int N = 1005;
const int LG = 11;
vector<int> a; int n;
int mask[N], dat[LG][N];
void dnc(int l, int r, int lev) {
if (l >= r) return ;
int m = (l+r) / 2;
dat[lev][m] = a[m];
for (int i = m-1; i >= l; i--)
dat[lev][i] = Secret(a[i], dat[lev][i+1]);
dat[lev][m+1] = a[m+1];
for (int i = m+2; i <= r; i++)
dat[lev][i] = Secret(dat[lev][i-1], a[i]);
for (int i = m+1; i <= r; i++)
mask[i] ^= 1<<lev;
dnc(l,m, lev+1);
dnc(m+1,r, lev+1);
}
void Init(int _n, int arr[]) {
n = _n;
a.insert(end(a), arr, arr+n);
dnc(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(dat[lev][L], dat[lev][R]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
101 ms |
2808 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
100 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 |
101 ms |
2808 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
353 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 |
356 ms |
4420 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
356 ms |
4468 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
360 ms |
4604 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
356 ms |
4352 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
354 ms |
4328 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
358 ms |
4436 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |