#include "secret.h"
int dp[1010][10];
//ans of i to i+(1<<j) to the right
//j=0->7
int arr[1010];
void Init(int N, int A[]) {
  for(int i=0;i<N;i++) arr[i]=A[i];
  for(int i=0;i<N-1;i++) dp[i][0]=Secret(A[i],A[i+1]);
  for(int i=0;i<N;i++){
    for(int j=1;j<=7;j++){
      if(i+(1<<j)>=N) break;
      dp[i][j]=Secret(dp[i][j-1],dp[dp[i][j-1]][j-1]);
    }
  }
}
int call(int a,int b){
  if(a==-1) return b;
  return Secret(a,b);
}
int Query(int L, int R) {
  int ans=-1;
  int now=L;
  while(now+(1<<7)<=R){
    ans=call(ans,dp[now][7]);
    now+=(1<<7)+1;
  }
  for(int i=7;i>=0;i--){
    if(now+(1<<i)<=R){
      ans=call(ans,dp[now][i]);
      now+=(1<<i)+1;
    }
  }
  if(now==R) ans=call(ans,arr[R]);
  return ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |