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;
const int N = 2e5+5;
int s,t;
struct A
{
int l,r;
long long ans;
};
A sm[N*4];
long long lz[N*4];
void apply(int now,int l,int r)
{
if(!lz[now]) return ;
sm[now].l+=lz[now];
sm[now].r+=lz[now];
if(l!=r) lz[now<<1]+=lz[now],lz[now<<1|1]+=lz[now];
lz[now] = 0;
}
A Merge(A a,A b)
{
if(a.r<b.l) return {a.l,b.r,a.ans+b.ans-s*(b.l-a.r)};
else return {a.l,b.r,a.ans+b.ans+t*(a.r-b.l)};
}
void upd(int l,int r,int ll,int rr,int now,int v)
{
apply(now,l,r);
if(l>rr||r<ll)return ;
if(l>=ll&&r<=rr)
{
lz[now]+=v;
apply(now,l,r);
return ;
}
int mid = (l+r) >> 1;
upd(l,mid,ll,rr,now<<1,v),upd(mid+1,r,ll,rr,now<<1|1,v);
sm[now] = Merge(sm[now<<1],sm[now<<1|1]);
// printf("%d %d %d %d %lld\n",l,r,sm[now].l,sm[now].r,sm[now].ans);
}
int main()
{
int n,q,l,r,x;
scanf("%d %d %d %d",&n,&q,&s,&t);
for(int i=0;i<=n;i++) scanf("%d",&x),upd(0,n,i,i,1,x);
// printf("%lld\n",sm[1].ans);
while(q--)
{
scanf("%d %d %d",&l,&r,&x);
upd(0,n,l,r,1,x);
printf("%lld\n",sm[1].ans);
}
return 0;
}
/*
3 5 1 2
0 4 1 8
1 2 2
1 1 -2
2 3 5
1 2 -1
1 3 5
*/
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d",&n,&q,&s,&t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:44:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0;i<=n;i++) scanf("%d",&x),upd(0,n,i,i,1,x);
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&l,&r,&x);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |