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;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
struct Seg {
ll siz = 1;
vector<ll> sums;
void init(int n){
while(siz < n)siz*=2;
sums.assign(siz * 2, 0LL);
}
void build(vector<ll>& arr , int x , int lx , int rx){
if(rx-lx==1){
if(lx < (int)arr.size()){
sums[x] = arr[lx];
}
return;
}
int m = (lx + rx) / 2;
build(arr , 2 * x + 1 , lx , m);
build(arr, 2 * x + 2 , m , rx);
sums[x] = max(sums[2 * x + 1] , sums[2 * x + 2]);
}
void build(vector<ll>& arr){
build(arr , 0 , 0 , siz);
}
void set(int i , int v , int x , int lx , int rx){
if(rx - lx ==1){
sums[x] = v;
return;
}
int m = (lx + rx) / 2;
if(i < m){
set(i , v , 2 * x + 1 , lx , m);
}
else {
set(i , v , 2 * x + 2 , m , rx);
}
sums[x]=max(sums[2 * x + 1] , sums[2 * x + 2]);
}
void set(int x , int y){
set(x ,y , 0 , 0 , siz);
}
ll sum(int l , int r , int x , int lx , int rx){
if(lx >= l && rx <= r){
return sums[x];
}
if(lx >= r || rx <= l)return 0;
int m = (lx + rx) / 2;
return max(sum(l , r , 2 * x + 1 , lx , m) , sum(l , r , 2 * x + 2 , m , rx));
}
ll sum(int l , int r){
return sum(l , r , 0 , 0 , siz);
}
};
void solve(){
int n,q;
cin >> n >> q;
vector<ll> arr(n);
for(int i = 0; i < n; i++)cin >> arr[i];
Seg st;
st.init(n + 5);
st.build(arr);
int t1;
cin >> t1;
for(int i = 0; i < n; i++){
arr[i] = st.sum(max(0,i-t1) , i + 1);
}
for(int i = 1; i < n; i++){
arr[i] += arr[i-1];
}
int l1,r1;
cin >> l1 >> r1;
cout << arr[r1-1] - (l1-2 >= 0 ? arr[l1-2] : 0) << '\n';
q--;
while(q--){
int t , l , r;
cin >> t >> l >> r;
l--;
r--;
cout << arr[r] - (l > 0 ? arr[l-1] : 0) << '\n';
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
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... |