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>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,q,S,T,x,sum,l,r,seg[4*N];
void ins(ll id,ll L,ll R,ll ql,ll qr,ll D){
if(L>=ql&&R<=qr){seg[id]+=D;return;}
if(L>=qr||R<=ql)return;
ll mid=(L+R)/2;
ins(id*2,L,mid,ql,qr,D);
ins(id*2+1,mid,R,ql,qr,D);
}
ll Q(ll id,ll L,ll R,ll to){
if(L==R-1)return seg[id];
ll mid=(L+R)/2;
if(to<mid){
return seg[id]+Q(id*2,L,mid,to);
}else{
return seg[id]+Q(id*2+1,mid,R,to);
}
}
ll ck(ll id){
if(id==n)return 0;
ll a=Q(1,0,n+1,id),b=Q(1,0,n+1,id+1);
return (a<b?-S*(b-a):(a-b)*T);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>q>>S>>T;
REP(i,n+1)cin>>x,ins(1,0,n+1,i,i+1,x);
REP(i,n+1)sum+=ck(i);
while(q--){
cin>>l>>r>>x;
sum-=(ck(l-1)+ck(r));
ins(1,0,n+1,l,r+1,x);
sum+=(ck(l-1)+ck(r));
cout<<sum<<"\n";
}
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... |