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>
#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[4*N];
void Get(Tree,int idx) {
if (idx<l || r<idx) return ; V+=v[h];
if (l==idx && r==idx) return ;
Get(left,idx),Get(right,idx);
}
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 () {
scanf("%I64d %I64d %I64d %I64d",&n,&q,&s,&t);
for (int i=0; i<=n; i++) {
scanf("%I64d",&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--) {
scanf("%I64d %I64d %I64d",&L,&R,&X);
if (R==n) {
V=0,Get(1,1,n,L-1),x=V;
V=0,Get(1,1,n,L),y=V;
RectL(x,y,X);
}
else {
V=0,Get(1,1,n,L-1),x=V;
V=0,Get(1,1,n,L),y=V;
RectL(x,y,X);
V=0,Get(1,1,n,R),x=V;
V=0,Get(1,1,n,R+1),y=V;
RectR(x,y,X);
}
Upd(1,1,n);
printf("%I64d\n",ANS);
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void Get(int, int, int, int)':
foehn_phenomena.cpp:10:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (idx<l || r<idx) return ; V+=v[h];
^~
foehn_phenomena.cpp:10: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:47:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:48:45: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
scanf("%I64d %I64d %I64d %I64d",&n,&q,&s,&t);
~~ ^
foehn_phenomena.cpp:48:45: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
foehn_phenomena.cpp:48:45: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
foehn_phenomena.cpp:48:45: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'long long int*' [-Wformat=]
foehn_phenomena.cpp:50:22: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
scanf("%I64d",&a[i]);
~~~~~^
foehn_phenomena.cpp:61:37: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
scanf("%I64d %I64d %I64d",&L,&R,&X);
~~ ^
foehn_phenomena.cpp:61:37: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
foehn_phenomena.cpp:61:37: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
foehn_phenomena.cpp:79:23: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
printf("%I64d\n",ANS);
^
foehn_phenomena.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%I64d %I64d %I64d %I64d",&n,&q,&s,&t);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%I64d",&a[i]);
~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%I64d %I64d %I64d",&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... |