#include "secret.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1<<10;
vector<int>segt(N*2,-1);
map<pair<int,int>,int>hintmem;
int hint(int x,int y){
if(x>y){
swap(x,y);
}
if(!hintmem.count({x,y})){
hintmem[{x,y}]=Secret(x,y);
}
return hintmem[{x,y}];
}
void Init(int n, int a[]) {
for(int i=0;i<n;i++){
segt[i+N]=a[i];
}
}
int f(int i){
if(segt[i]>=0){
return segt[i];
}
segt[i]=hint(f(i*2),f(i*2+1));
return segt[i];
}
int Query(int l, int r) {
l+=N;
r+=N;
vector<int>v;
while(l<=r){
if(l%2==1){
v.push_back(f(l++));
}
if(r%2==0){
v.push_back(f(r--));
}
l/=2;
r/=2;
}
int res=v.back();
v.pop_back();
for(int x:v){
res=hint(res,x);
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |