Submission #317262

#TimeUsernameProblemLanguageResultExecution timeMemory
317262nandonathanielFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
652 ms19832 KiB
#include<bits/stdc++.h> using namespace std; typedef long long LL; const LL MAXN=200005; LL tree[4*MAXN],lazy[4*MAXN]; LL A[MAXN]; void updatenode(LL now,LL L,LL R,LL val){ tree[now]+=((R-L+1)*val); lazy[now]+=val; } void pushdown(LL now,LL L,LL R){ LL mid=(L+R)/2; updatenode(2*now,L,mid,lazy[now]); updatenode(2*now+1,mid+1,R,lazy[now]); lazy[now]=0; } void build(LL now,LL L,LL R){ if(L==R){ tree[now]=A[L]; return; } LL mid=(L+R)/2; build(2*now,L,mid); build(2*now+1,mid+1,R); tree[now]=tree[2*now]+tree[2*now+1]; } LL query(LL now,LL L,LL R,LL x,LL y){ if(L>=x && R<=y)return tree[now]; if(L>y || R<x)return 0; pushdown(now,L,R); LL mid=(L+R)/2; return query(2*now,L,mid,x,y)+query(2*now+1,mid+1,R,x,y); } void update(LL now,LL L,LL R,LL x,LL y,LL val){ if(L>=x && R<=y){ updatenode(now,L,R,val); return; } if(L>y || R<x)return; LL mid=(L+R)/2; pushdown(now,L,R); update(2*now,L,mid,x,y,val); update(2*now+1,mid+1,R,x,y,val); tree[now]=tree[2*now]+tree[2*now+1]; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); LL N,Q,S,T,L,R,P,U,V,W,X; cin >> N >> Q >> S >> T; for(LL i=0;i<=N;i++)cin >> A[i]; build(1,1,N); LL ans=0; for(LL i=1;i<=N;i++){ if(A[i-1]<=A[i])ans-=(S*(A[i]-A[i-1])); else ans+=(T*(A[i-1]-A[i])); } while(Q--){ cin >> L >> R >> P; LL U=0,V=query(1,1,N,L,L); if(L>=2)U=query(1,1,N,L-1,L-1); if(U<=V)ans+=(S*(V-U)); else ans-=(T*(U-V)); LL W=query(1,1,N,R,R),X; if(R+1<=N){ X=query(1,1,N,R+1,R+1); if(W<=X)ans+=(S*(X-W)); else ans-=(T*(W-X)); } update(1,1,N,L,R,P); V=query(1,1,N,L,L); W=query(1,1,N,R,R); if(U<=V)ans-=(S*(V-U)); else ans+=(T*(U-V)); if(R+1<=N){ if(W<=X)ans-=(S*(X-W)); else ans+=(T*(W-X)); } cout << ans << '\n'; } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:56:19: warning: unused variable 'U' [-Wunused-variable]
   56 |  LL N,Q,S,T,L,R,P,U,V,W,X;
      |                   ^
foehn_phenomena.cpp:56:21: warning: unused variable 'V' [-Wunused-variable]
   56 |  LL N,Q,S,T,L,R,P,U,V,W,X;
      |                     ^
foehn_phenomena.cpp:56:23: warning: unused variable 'W' [-Wunused-variable]
   56 |  LL N,Q,S,T,L,R,P,U,V,W,X;
      |                       ^
foehn_phenomena.cpp:56:25: warning: unused variable 'X' [-Wunused-variable]
   56 |  LL N,Q,S,T,L,R,P,U,V,W,X;
      |                         ^
foehn_phenomena.cpp:84:19: warning: 'X' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |    else ans+=(T*(W-X));
      |                 ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...