#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;int Q;
int ar[200005];
int rmq[22][200005];
int chmx(int l,int r){
int lg=__lg(r-l+1);
return max(rmq[lg][l],rmq[lg][r-(1<<lg)+1]);
}
signed main()
{
cin>>n>>Q;
for(int i=1;i<=n;i++){
cin>>ar[i];
rmq[0][i]=ar[i];
}
for(int i=1;i<=21;i++){
for(int j=1;j+(1<<i)-1<=n;j++){
rmq[i][j]=max(rmq[i-1][j],rmq[i-1][j+(1<<(i-1))]);
}
}
while(Q--){
int t;int l;int r;
cin>>t>>l>>r;
l=max(1ll,r-t);
int ans=0;
for(int i=l;i<=r;i++){
ans+=chmx(max(1ll,i-t),i);
}
cout<<ans<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1064 ms |
27504 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1081 ms |
27452 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
26944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |