Submission #209270

#TimeUsernameProblemLanguageResultExecution timeMemory
209270jzhFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
170 ms5752 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll ft[2000005]; ll ls(ll x) { return (x & (-x)); } ll query(ll p) { ll sum = 0; for(; p; p -= ls(p)) sum += ft[p]; return sum; } void update(ll x, ll y, ll v) { for(; x < 2000005; x += ls(x)) ft[x] += v; y++; for(; y < 2000005; y += ls(x)) ft[y] -= v;} int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll n,q,i,s,t,i1,x,y,w,sum=0,xi,yi; cin>>n>>q>>s>>t; ll arr[n+1]; for (i=0;i<=n;i++){ cin>>arr[i]; if (i>0)update(i,i,arr[i]); } for (i=1;i<=n;i++){ if (arr[i]>arr[i-1])sum-=s*(arr[i]-arr[i-1]); else sum+=t*(arr[i-1]-arr[i]); } //cout<<sum<<'\n'; //cout<<query(0)<<'\n'; while (q--){ cin>>x>>y>>w; xi=query(x)-query(x-1); if (y!=n)yi=query(y+1)-query(y); else yi=0; if (xi>0)sum+=s*xi; else sum+=t*xi; if (yi>0)sum+=s*yi; else sum+=t*yi; update(x,y,w); if (query(x)<0)update(x,x,-1*query(x)); if (query(y)<0)update(y,y,-1*query(y)); xi=query(x)-query(x-1); if (y!=n)yi=query(y+1)-query(y); else yi=0; if (xi>0)sum-=s*xi; else sum-=t*xi; if (yi>0)sum-=s*yi; else sum-=t*yi; cout<<sum<<'\n'; } }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:21:18: warning: unused variable 'i1' [-Wunused-variable]
     ll n,q,i,s,t,i1,x,y,w,sum=0,xi,yi;
                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...