#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 300007;
const ll inf = 2e9;
const ll mod = 1e9+7;
const double pi = acos(-1);
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;
#include "secret.h"
int n, a[M];
vector <int> suf[M], pref[M];
void build(int node = 1, int l = 1, int r = n){
if(l == r){
suf[node].pb(a[l]);
return;
}
int mid = (l + r) / 2;
build(2 * node, l, mid);
build(2 * node + 1, mid + 1, r);
int x = a[mid];
suf[node].pb(x);
for(int i = mid - 1; i >= l; --i){
x = Secret(a[i], x);
suf[node].pb(x);
}
x = a[mid + 1];
pref[node].pb(x);
for(int i = mid + 2; i <= r; ++i){
x = Secret(x, a[i]);
pref[node].pb(x);
}
return;
}
void Init(int N, int A[]){
n = N;
for(int i = 1; i <= n; ++i) a[i] = A[i - 1];
build();
return;
}
int get(int st, int en, int node = 1, int l = 1, int r = n){
int mid = (l + r) / 2;
if(st <= mid && en > mid){
return Secret(suf[node][mid - st], pref[node][en - mid - 1]);
}
if(en <= mid) return get(st, en, 2 * node, l, mid);
return get(st, en, 2 * node + 1, mid + 1, r);
}
int Query(int L, int R){
if(L == R) return a[L + 1];
return get(L + 1, R + 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
16456 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
130 ms |
16456 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
134 ms |
16460 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
439 ms |
18484 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
446 ms |
18448 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
448 ms |
18428 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
447 ms |
18396 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
447 ms |
18432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
443 ms |
18496 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
441 ms |
18472 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |