#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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
105 ms |
5740 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
98 ms |
5420 KB |
Output is correct |
3 |
Correct |
103 ms |
6848 KB |
Output is correct |
4 |
Correct |
93 ms |
3916 KB |
Output is correct |
5 |
Correct |
97 ms |
6728 KB |
Output is correct |
6 |
Correct |
92 ms |
3912 KB |
Output is correct |
7 |
Correct |
90 ms |
3912 KB |
Output is correct |
8 |
Correct |
93 ms |
3816 KB |
Output is correct |
9 |
Correct |
95 ms |
3912 KB |
Output is correct |
10 |
Correct |
101 ms |
7112 KB |
Output is correct |
11 |
Correct |
93 ms |
3860 KB |
Output is correct |
12 |
Correct |
89 ms |
3912 KB |
Output is correct |
13 |
Correct |
100 ms |
7064 KB |
Output is correct |
14 |
Correct |
95 ms |
6984 KB |
Output is correct |
15 |
Correct |
90 ms |
3912 KB |
Output is correct |
16 |
Correct |
101 ms |
3656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
103 ms |
4012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |