#include <bits/stdc++.h>
using namespace std;
int Secret(int l, int r);
vector<vector<int>>dvc;
vector<int>arr;
void dc(int l, int r, int lvl){
if(l==r){
dvc[lvl][l]=arr[l];
return;
}
int mid=(l+r)>>1;
dvc[lvl][mid]=arr[mid];
for(int i=mid-1;i>=l;i--){
dvc[lvl][i]=Secret(arr[i],dvc[lvl][i+1]);
}
dvc[lvl][mid+1]=arr[mid+1];
for(int i=mid+2;i<=r;i++){
dvc[lvl][i]=Secret(dvc[lvl][i-1],arr[i]);
}
dc(l,mid,lvl+1);
dc(mid+1,r,lvl+1);
}
int retorno(int a,int b,int l,int r, int lvl){
if(a==b){
return dvc[lvl][l];
}
int mid=(a+b)>>1;
if(r<(mid+1)){
return retorno(a,mid,l,r,lvl+1);
}
else if(l>mid){
return retorno(mid+1,b,l,r,lvl+1);
}
return Secret(dvc[lvl][l],dvc[lvl][r]);
}
void Init(int n, int a[]){
arr.resize(n);
for(int i=0;i<n;i++){
arr[i]=a[i];
}
dvc.resize(15,vector<int>(n));
dc(0,n-1,0);
}
int Query(int l,int r){
return retorno(0,arr.size()-1,l,r,0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
2384 KB |
Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1 |
2 |
Correct |
76 ms |
2384 KB |
Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1 |
3 |
Correct |
81 ms |
2304 KB |
Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1 |
4 |
Correct |
282 ms |
4440 KB |
Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1 |
5 |
Correct |
281 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
6 |
Correct |
278 ms |
4280 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
7 |
Correct |
281 ms |
4384 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
8 |
Correct |
279 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 |
271 ms |
4356 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |
10 |
Correct |
272 ms |
4432 KB |
Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1 |