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 long long mod=998244353;
long long n,q,s,t,tree[800005],lazy[800005],ans;
void up(int nod,int l,int r,int x,int y,long long val)
{
if(lazy[nod]!=0)
{
tree[nod]+=(r-l+1)*lazy[nod];
if(l!=r)
{
lazy[nod*2]+=lazy[nod];
lazy[nod*2+1]+=lazy[nod];
}
lazy[nod]=0;
}
if(r<x||y<l)return;
if(x<=l&&r<=y)
{
tree[nod]+=(r-l+1)*val;
if(l!=r)
{
lazy[nod*2]+=val;
lazy[nod*2+1]+=val;
}
return;
}
int mid=(l+r)/2;
up(nod*2,l,mid,x,y,val);
up(nod*2+1,mid+1,r,x,y,val);
tree[nod]=tree[nod*2]-tree[nod*2+1];
}
long long qu(int nod,int l,int r,int x,int y)
{
if(r<x||y<l)return 0;
if(lazy[nod]!=0)
{
tree[nod]+=(r-l+1)*lazy[nod];
if(l!=r)
{
lazy[nod*2]+=lazy[nod];
lazy[nod*2+1]+=lazy[nod];
}
lazy[nod]=0;
}
if(x<=l&&r<=y)return tree[nod];
int mid=(l+r)/2;
return qu(nod*2,l,mid,x,y)-qu(nod*2+1,mid+1,r,x,y);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n>>q>>s>>t;
long long b;
cin>>b;
up(1,0,n,0,0,b);
for(int i=0;i<n;i++)
{
long long a;
cin>>a;
long long dif=b-a;
if(dif>=0)ans+=dif*t;
else ans+=dif*s;
up(1,0,n,i+1,i+1,a);
b=a;
}
int l,r;
long long x,oa,ob,a,c,d,dif;
while(q--)
{
cin>>l>>r>>x;
oa=qu(1,0,n,l-1,l),ob=-qu(1,0,n,r,r+1);
up(1,0,n,l,r,x);
a=oa-x,b=ob+x;
if(l>0)
{
if(oa>=0)ans-=oa*t;
else ans-=oa*s;
if(a>=0)ans+=a*t;
else ans+=a*s;
}
if(r<n)
{
if(ob>=0)ans-=ob*t;
else ans-=ob*s;
if(b>=0)ans+=b*t;
else ans+=b*s;
}
cout<<ans<<endl;
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:72:25: warning: unused variable 'c' [-Wunused-variable]
long long x,oa,ob,a,c,d,dif;
^
foehn_phenomena.cpp:72:27: warning: unused variable 'd' [-Wunused-variable]
long long x,oa,ob,a,c,d,dif;
^
foehn_phenomena.cpp:72:29: warning: unused variable 'dif' [-Wunused-variable]
long long x,oa,ob,a,c,d,dif;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |