#include "secret.h"
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
const int maxn = 1005;
int pfx[4*maxn][maxn], sfx[4*maxn][maxn];
int arr[maxn];
int n;
void build(int l, int r, int id){
if(r-l<=1)return;
int mid = (l+r)>>1;
pfx[id][0]=arr[mid+1];
sfx[id][0]=arr[mid];
for(int i = mid+2; i <= r; i++){
pfx[id][i-mid-1]=Secret(pfx[id][i-mid-2], arr[i]);
}
for(int i = 1; i < mid+1-l; i++){
sfx[id][i]=Secret(arr[mid-i], sfx[id][i-1]);
}
build(l, mid, id<<1);
build(mid+1, r, id<<1|1);
}
int gt(int l, int r, int ql, int qr, int id){
int mid = (l+r)>>1;
if(qr < mid)return gt(l, mid, ql, qr, id<<1);
else if(ql > mid+1)return gt(mid+1, r, ql, qr, id<<1|1);
else{
int re = -1;
if(ql <= mid)re = sfx[id][mid-ql];
if(qr >= mid+1){
if(re < 0)re = pfx[id][qr-mid-1];
else re = Secret(re, pfx[id][qr-mid-1]);
}
return re;
}
}
int Query(int L, int R){
if(L==R)return arr[L];
else if(R-1==L)return Secret(arr[L], arr[R]);
else return gt(0, n-1, L, R, 1);
}
void Init(int N, int A[]){
n = N;
for(int i = 0; i < n; i++)arr[i]=A[i];
build(0, n-1, 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
4444 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
124 ms |
4320 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
136 ms |
4308 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
441 ms |
8340 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
459 ms |
8368 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
457 ms |
8272 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 |
8380 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
453 ms |
8256 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
436 ms |
8312 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
449 ms |
8236 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |