Submission #114266

#TimeUsernameProblemLanguageResultExecution timeMemory
114266jhnah917Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
204 ms7292 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, q; ll S, T; ll ans; vector<ll> v; struct BIT{ ll tree[202020]; void update(int x, ll v){ x++; while(x < 202020){ tree[x] += v; x += x & -x; } } ll query(int x){ ll ret = 0; x++; while(x){ ret += tree[x]; x -= x & -x; } return ret; } void update(int l, int r, ll v){ update(l, v); update(r+1, -v); } }seg; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q >> S >> T; v.resize(n+1); for(int i=0; i<=n; i++){ cin >> v[i]; seg.update(i, i, v[i]); } for(int i=0; i<n; i++){ if(v[i] < v[i+1]) ans -= (v[i+1] - v[i]) * S; else ans += (v[i] - v[i+1]) * T; } while(q--){ int s, e, x; cin >> s >> e >> x; if(s != 0){ int prv = seg.query(s-1); int now = seg.query(s); if(prv < now) ans -= (prv - now) * S; else ans += (now - prv) * T; } if(e != n){ int prv = seg.query(e); int now = seg.query(e+1); if(prv < now) ans -= (prv - now) * S; else ans += (now - prv) * T; } seg.update(s, e, x); if(s != 0){ int prv = seg.query(s-1); int now = seg.query(s); if(prv < now) ans -= (now - prv) * S; else ans += (prv - now) * T; } if(e != n){ int prv = seg.query(e); int now = seg.query(e+1); if(prv < now) ans -= (now - prv) * S; else ans += (prv - now) * T; } cout << ans << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...