Submission #484047

#TimeUsernameProblemLanguageResultExecution timeMemory
484047ponytailFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
753 ms11820 KiB
#include "bits/stdc++.h" using namespace std; const int MAXN = 200010; struct node { int upd = 0, ans = 0; } a[4*MAXN]; void update(int l, int r, int constl, int constr, int idx, int val) { if(l<=constl && constr<=r) { a[idx].upd += val; a[idx].ans += val; return; } int mid = (constl+constr)>>1; if(mid<l || r<constl) update(l, r, mid+1, constr, 2*idx+2, val); else if(constr<l || r<mid+1) update(l, r, constl, mid, 2*idx+1, val); else { update(l, r, constl, mid, 2*idx+1, val); update(l, r, mid+1, constr, 2*idx+2, val); } a[idx].ans = a[idx].upd + min(a[2*idx+1].ans, a[2*idx+2].ans); } int query(int l, int r, int constl, int constr, int idx) { if(l<=constl && constr<=r) return a[idx].ans; int mid = (constl+constr)>>1; if(mid<l || r<constl) return a[idx].upd + query(l, r, mid+1, constr, 2*idx+2); else if(constr<l || r<mid+1) return a[idx].upd + query(l, r, constl, mid, 2*idx+1); else { return a[idx].upd + min(query(l, r, constl, mid, 2*idx+1), query(l, r, mid+1, constr, 2*idx+2)); } } int main() { int N, Q, S, T; cin >> N >> Q >> S >> T; int cnt0 = 0, cnt1 = 0; for(int i=0; i<=N; i++) { int ono; cin >> ono; update(i, i, 0, MAXN-1, 0, ono); } for(int i=1; i<=N; i++) { if(query(i-1, i-1, 0, MAXN-1, 0) < query(i, i, 0, MAXN-1, 0)) cnt0 += query(i, i, 0, MAXN-1, 0) - query(i-1, i-1, 0, MAXN-1, 0); else cnt1 += query(i-1, i-1, 0, MAXN-1, 0) - query(i, i, 0, MAXN-1, 0); } while(Q--) { int l, r, x; cin >> l >> r >> x; if(query(l-1, l-1, 0, MAXN-1, 0) < query(l, l, 0, MAXN-1, 0)) cnt0 -= query(l, l, 0, MAXN-1, 0) - query(l-1, l-1, 0, MAXN-1, 0); else cnt1 -= query(l-1, l-1, 0, MAXN-1, 0) - query(l, l, 0, MAXN-1, 0); if(r<N) { if(query(r, r, 0, MAXN-1, 0) < query(r+1, r+1, 0, MAXN-1, 0)) cnt0 -= query(r+1, r+1, 0, MAXN-1, 0) - query(r, r, 0, MAXN-1, 0); else cnt1 -= query(r, r, 0, MAXN-1, 0) - query(r+1, r+1, 0, MAXN-1, 0); } update(l, r, 0, MAXN-1, 0, x); if(query(l-1, l-1, 0, MAXN-1, 0) < query(l, l, 0, MAXN-1, 0)) cnt0 += query(l, l, 0, MAXN-1, 0) - query(l-1, l-1, 0, MAXN-1, 0); else cnt1 += query(l-1, l-1, 0, MAXN-1, 0) - query(l, l, 0, MAXN-1, 0); if(r<N) { if(query(r, r, 0, MAXN-1, 0) < query(r+1, r+1, 0, MAXN-1, 0)) cnt0 += query(r+1, r+1, 0, MAXN-1, 0) - query(r, r, 0, MAXN-1, 0); else cnt1 += query(r, r, 0, MAXN-1, 0) - query(r+1, r+1, 0, MAXN-1, 0); } cout << -cnt0 * S + cnt1 * T << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...