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<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>
#define ll long long
#define LL __int128_t
#define DB double
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (ll)(1e9)
#define MOD (ll)(1e9+7)
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
template<class T> using PQ=priority_queue<T,vector<T>,less<T> >;
void file(){
freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
}
int s[200005],seg[800005];
void build(int id,int l,int r){
if(l==r){
seg[id]=s[l]; return;
}
int mid=(l+r)>>1;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
seg[id]=max(seg[id*2],seg[id*2+1]);
}
int ask(int id,int l,int r,int L,int R){
if(l>R||r<L) return 0;
if(L<=l&&r<=R) return seg[id];
int mid=(l+r)>>1;
return max(ask(id*2,l,mid,L,R),ask(id*2+1,mid+1,r,L,R));
}
int t[200005],l[200005],r[200005];
ll pre[200005];
signed main(){
AC;
int n,q; cin>>n>>q;
FOR(i,1,n+1) cin>>s[i];
build(1,1,n);
FOR(i,0,q){
cin>>t[i]>>l[i]>>r[i];
}
FOR(i,1,n+1){
pre[i]=pre[i-1]+ask(1,1,n,i-t[0],i);
}
FOR(i,0,q) cout<<pre[r[i]]-pre[l[i]-1]<<endl;
}
/*
*/
Compilation message (stderr)
ho_t5.cpp: In function 'void file()':
ho_t5.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen("/Users/liaoyunyang/Desktop/meta_in.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t5.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen("/Users/liaoyunyang/Desktop/meta_out.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |