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 = 200*1000+7;
long long a[N];
long long t[2][4*N];
long long T[4*N];
long long f[4*N];
inline void push(int v,int s,int e){
if(f[v]){
T[v] += ((e-s+1)*f[v]);
if(s!=e){
f[v*2] += f[v];
f[v*2+1] += f[v];
}
}
f[v] = 0;
}
inline void update(int v,int s,int e,int l,int r,long long val){
if(l>r) return;
push(v,s,e);
if(s == l && e == r){
f[v] += val;
return;
}
int m = (s+e)/2;
update(v*2,s,m,l,min(m,r),val);
update(v*2+1,m+1,e,max(l,m+1),r,val);
push(v*2,s,m);
push(v*2+1,m+1,e);
T[v] = T[v*2]+T[v*2+1];
}
inline long long query(int v,int s,int e,int l,int r){
if(l>r) return 0;
push(v,s,e);
if(s == l && e == r) return T[v];
int m = (s+e)/2;
return query(v*2,s,m,l,min(m,r))+query(v*2+1,m+1,e,max(l,m+1),r);
}
int n;
inline long long sum(int nshan,int r){
long long res = 0;
for (; r > 0; r = (r & (r+1)) - 1)
res += t[nshan][r];
return res;
}
inline long long query2(int nshan,int l,int r){
return sum(nshan,r)-sum(nshan,l-1);
}
inline long long update2(int nshan,int i,long long val){
long long dw = query2(nshan,i,i);
val-=dw;
for (; i <= n; i = (i | (i+1)))
t[nshan][i] += val;
}
int main(){
int q;
long long ss,tt;
scanf("%d%d%lld%lld",&n,&q,&ss,&tt);
for(int i = 0;i<=n;i++){
scanf("%lld",&a[i]);
update(1,0,n,i,i,a[i]);
}
for(int i = 1;i<=n;i++){
long long df = a[i-1]-a[i];
if(df>=0){
update2(1,i,df);
}
else{
update2(0,i,df);
}
}
while(q--){
int l,r;
long long val;
scanf("%d%d%lld",&l,&r,&val);
update2(0,l,0);
update2(1,l,0);
update(1,0,n,l,r,val);
long long x = query(1,0,n,l,l);
long long y = query(1,0,n,l-1,l-1);
y-=x;
if(y<0) {
update2(0,l,y);
}
else{
update2(1,l,y);
}
if(r<n){
update2(0,r+1,0);
update2(1,r+1,0);
x = query(1,0,n,r,r);
y = query(1,0,n,r+1,r+1);
x-=y;
if(x<0){
update2(0,r+1,x);
}
else{
update2(1,r+1,x);
}
}
long long w = query2(0,1,n);
w*=ss;
long long e = query2(1,1,n);
e*=tt;
w+=e;
printf("%lld\n",w);
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'long long int update2(int, int, long long int)':
foehn_phenomena.cpp:54:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld%lld",&n,&q,&ss,&tt);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[i]);
~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld",&l,&r,&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... |