# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
959487 | irmuun | Secret (JOI14_secret) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "Secret.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int n;
vector<pair<int,int>>v;
int val[1005][1005];
void build(int l,int r){
val[l][r]=Secret(l,r);
if(l==r) return;
int mid=(l+r)/2;
build(l,mid);
build(mid+1,r);
}
void ask(int l,int r,int L,int R){
if(l<r||R<l||r<L) return;
if(L<=l&&r<=R){
v.pb({l,r});
return;
}
int mid=(l+r)/2;
ask(l,mid,L,R);
ask(mid+1,r,L,R);
}
void Init(int N,int A[]){
n=N;
build(1,N);
}
int Query(int l,int r){
v.clear();
ask(1,n,l,r);
int ans=val[v[0].ff][v[0].ss];
for(int i=1;i<v.size();i++){
ans=Secret(ans,val[v[i].ff][v[i].ss]);
}
return ans;
}