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>
using namespace std;
int tr[400000];
int n,q;
void add(int p,int w)
{
p+=n;
tr[p] = w;
p/=2;
while(p > 0)
{
tr[p] = max(tr[p*2],tr[p*2+1]);
p/=2;
}
}
int spr(int l,int r)
{
l+=n;r+=n;
int ans = 0;
ans = max(ans, tr[l]);
ans = max(ans, tr[r]);
while(l/2 != r/2)
{
if(l%2 == 0) ans = max(ans,tr[l+1]);
if(r%2 == 1) ans = max(ans,tr[r-1]);
l/=2;r/=2;
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>q;
for(int i = 0;i<n;i++)
{
int x;
cin>>x;
add(i,x);
}
for(int i = 0;i<q;i++)
{
int t,l,r;
cin>>t>>l>>r;
l--;r--;
cout<<spr(max(0,l-t),r)<<"\n";
}
}
# | 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... |