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;
struct Q{
long long l, r, time, index;
};
bool comp(const Q &q1, const Q &q2){
return q1.time<q2.time;
}
long long tree[400'007];
void Update(long long v, long long l, long long r, long long vl, long long vr, long long val){
if (vl>r||vr<l) return;
if (vl>=l&&vr<=r){
tree[v]=max(tree[v], val);
return;
}
long long mid=(vl+vr)/2;
Update(v*2, l, r, vl, mid, val);
Update(v*2+1, l, r, mid+1, vr, val);
}
long long Get(long long v){
long long out=-1;
while (v>0){
out=max(out, tree[v]);
v/=2;
}
return out;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (long long i=0;i<400'007;i++) tree[i]=-1;
long long n, q;
cin>>n>>q;
long long trsize=1;
while (trsize<n) trsize<<=1;
for (long long i=0;i<n;i++){
cin>>tree[trsize+i];
}
vector<Q> qv(q);
for (long long i=0;i<q;i++){
cin>>qv[i].time>>qv[i].l>>qv[i].r;
qv[i].index=i;
}
sort(qv.begin(), qv.end(), comp);
long long t=0;
vector<long long> out(q);
for (Q qe:qv){
long long tDiff=qe.time-t;
t=qe.time;
for (long long i=n-tDiff-1;i>=0;i--){
Update(1, trsize+i, trsize+i+tDiff, trsize, trsize*2-1, Get(trsize+i));
}
out[qe.index]=Get(trsize+qe.l-1);
}
for (long long x:out) cout<<x<<'\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... |