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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int tree[400007];
void Treeify(int trsize){
for (int i=trsize-1;i>0;i--) tree[i]=max(tree[2*i], tree[2*i+1]);
}
int Get(int v, int l, int r, int vl, int vr){
if (vl>r||vr<l) return 0;
if (vl>=l&&vr<=r){
return tree[v];
}
if (tree[vr]==5){
v=v;
}
int mid=(vl+vr)/2;
int lson=Get(v*2, l, r, vl, mid);
int rson=Get(v*2+1, l, r, mid+1, vr);
return max(lson, rson);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i=0;i<400007;i++) tree[i]=0;
int n, q;
cin>>n>>q;
int trsize=1;
while (trsize<n) trsize<<=1;
for (int i=0;i<n;i++){
cin>>tree[trsize+i];
}
Treeify(trsize);
for (int i=1;i<=trsize*2+1;i++) cout<<tree[i]<<" ";
cout<<'\n';
for (int qe=0;qe<q;qe++){
int t, l, r;
cin>>t>>l>>r;
l=max(0, l-t);
cout<<Get(1, trsize+l, trsize+r, trsize, trsize*2+1)<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |