#include "bits/stdc++.h"
#include "secret.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif
const int M = 1005;
int a[M], NN;
int ask(int a, int b){
return Secret(a, b);
}
struct ST{
int pref[M<<2][M], suff[M<<2][M];
void build(int lx, int rx, int x){
//~ cout<<lx<<" "<<rx<<"\n";
if(lx == rx) return;
int m = (lx + rx) >> 1;
pref[x][m] = a[m];
for(int p=m-1;p>=lx;p--){
pref[x][p] = ask(a[p], pref[x][p+1]);
}
suff[x][m+1] = a[m+1];
for(int p=m+2;p<=rx;p++){
suff[x][p] = ask(suff[x][p-1], a[p]);
}
//~ cout<<ask(ask(a[0], a[1]), ask(a[2], a[3]))<<"\n";
//~ cout<<lx<<" "<<rx<<" "<<ask(pref[x][lx], suff[x][rx])<<"\n";
build(lx, m, x<<1);
build(m+1, rx, x<<1|1);
}
int get(int l, int r, int lx, int rx, int x){
if(lx == rx) return a[lx];
int m = (lx + rx) >> 1;
if(r <= m) return get(l, r, lx, m, x<<1);
if(m < l) return get(l, r, m+1, rx, x<<1|1);
return ask(pref[x][l], suff[x][r]);
}
}tree;
void Init(int N, int A[]) {
NN = N;
for(int i=0;i<N;i++){
a[i] = A[i];
}
tree.build(0, NN - 1, 1);
}
int Query(int L, int R) {
return tree.get(L, R, 0, NN - 1, 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
6396 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 |
6456 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
124 ms |
6368 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
449 ms |
12208 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
437 ms |
12228 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
438 ms |
12180 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
438 ms |
12188 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
436 ms |
12096 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
9 |
Correct |
437 ms |
12228 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
432 ms |
12100 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |