This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define left 2*h,l,(l+r)/2
#define right 2*h+1,(l+r)/2+1,r
using namespace std;
const int N=2e5+5;
long long n,q,s,t,L,R,X,ANS,idx,x,y,V=0;
long long a[N],v[6*N];
void Get(Tree) {
if (idx<l || r<idx) return ; V+=v[h];
if (l==idx && r==idx) return ;
Get(left),Get(right);
}
void Upd(Tree) {
if (R<l || r<L) return ;
if (L<=l && r<=R) { v[h]+=X; return ; }
Upd(left),Upd(right);
}
void RectL(long long x,long long y,long long X) {
if (x<y) {
ANS+=(y-x)*s;
y+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
else {
ANS-=(x-y)*t;
y+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
}
void RectR(long long x,long long y,long long X) {
if (x<y) {
ANS+=(y-x)*s;
x+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
else {
ANS-=(x-y)*t;
x+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
}
main () {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>q>>s>>t;
for (int i=0; i<=n; i++) {
cin>>a[i];
if (i) {
if (a[i-1]<a[i]) ANS-=(a[i]-a[i-1])*s;
else ANS+=(a[i-1]-a[i])*t;
L=i,R=i,X=a[i];
Upd(1,1,n);
}
}
while (q--) {
cin>>L>>R>>X;
if (R==n) {
idx=L-1,V=0,Get(1,1,n),x=V;
idx=L,V=0,Get(1,1,n),y=V;
RectL(x,y,X);
}
else {
idx=L-1,V=0,Get(1,1,n),x=V;
idx=L,V=0,Get(1,1,n),y=V;
RectL(x,y,X);
idx=R,V=0,Get(1,1,n),x=V;
idx=R+1,V=0,Get(1,1,n),y=V;
RectR(x,y,X);
}
Upd(1,1,n);
cout<<ANS<<"\n";
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void Get(int, int, int)':
foehn_phenomena.cpp:12:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (idx<l || r<idx) return ; V+=v[h];
^~
foehn_phenomena.cpp:12:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (idx<l || r<idx) return ; V+=v[h];
^
foehn_phenomena.cpp: At global scope:
foehn_phenomena.cpp:49:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |