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 N 200005
struct A{
long long l,r,up,dow;
};
A t[4*N];
long long a[N],lazy[N],s,tt,ll,rr,val;
void push(int x){
if(lazy[x]){
lazy[x*2]+=lazy[x];
lazy[x*2+1]+=lazy[x];
t[x*2].l+=lazy[x];
t[x*2].r+=lazy[x];
t[x*2+1].l+=lazy[x];
t[x*2+1].r+=lazy[x];
lazy[x]=0;
}
}
void cre(int x,int l,int r){
if(l==r){t[x].l=t[x].r=a[l];return ;}
int mid=(l+r)/2;
cre(x*2,l,mid);
cre(x*2+1,mid+1,r);
t[x].l=t[x*2].l;
t[x].r=t[x*2+1].r;
t[x].up=t[x*2].up+t[x*2+1].up;
t[x].dow=t[x*2].dow+t[x*2+1].dow;
if(t[x*2].r<t[x*2+1].l)t[x].up+=t[x*2+1].l-t[x*2].r;
else t[x].dow+=t[x*2].r-t[x*2+1].l;
}
void upd(int x,int l,int r){
if(l>rr||ll>r)return ;
if(ll<=l&&r<=rr){
t[x].l+=val;
t[x].r+=val;
lazy[x]+=val;
return ;
}
push(x);
int mid=(l+r)/2;
upd(x*2,l,mid);
upd(x*2+1,mid+1,r);
t[x].l=t[x*2].l;
t[x].r=t[x*2+1].r;
t[x].up=t[x*2].up+t[x*2+1].up;
t[x].dow=t[x*2].dow+t[x*2+1].dow;
if(t[x*2].r<t[x*2+1].l)t[x].up+=t[x*2+1].l-t[x*2].r;
else t[x].dow+=t[x*2].r-t[x*2+1].l;
}
A sol(int x,int l,int r){
if(l>rr||ll>r)return {(long long)1e18};
if(ll<=l&&r<=rr)return t[x];
push(x);
int mid=(l+r)/2;
A tl=sol(x*2,l,mid),tr=sol(x*2+1,mid+1,r),tx;
if(tl.l==1e18)return tr;
else if(tr.l==1e18)return tl;
tx.l=tl.l;
tx.r=tr.r;
tx.up=tl.up+tr.up;
tx.dow=tl.dow+tr.dow;
if(tl.r<tr.l)tx.up+=tr.l-tl.r;
else tr.dow+=tl.r-tr.l;
}
int main(){
int n,q,i;
scanf("%d %d %lld %lld",&n,&q,&s,&tt);
n++;
for(i=1;i<=n;i++)scanf("%lld",&a[i]);
cre(1,1,n);
while(q--){
scanf("%d %d %lld",&ll,&rr,&val);
ll++,rr++;
upd(1,1,n);
//A ans=sol(1,1,n);
A ans=t[1];
printf("%lld\n",-ans.up*s+ans.dow*tt);
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:80:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
80 | scanf("%d %d %lld",&ll,&rr,&val);
| ~^ ~~~
| | |
| int* long long int*
| %lld
foehn_phenomena.cpp:80:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
80 | scanf("%d %d %lld",&ll,&rr,&val);
| ~^ ~~~
| | |
| int* long long int*
| %lld
foehn_phenomena.cpp: In function 'A sol(int, int, int)':
foehn_phenomena.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
71 | }
| ^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | scanf("%d %d %lld %lld",&n,&q,&s,&tt);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:77:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
77 | for(i=1;i<=n;i++)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d %d %lld",&ll,&rr,&val);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |