Submission #33267

#TimeUsernameProblemLanguageResultExecution timeMemory
33267minhtung0404Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
423 ms28580 KiB
#include<bits/stdc++.h> const int N = 2e5 + 5; using namespace std; struct node { long long l, r, val, lazy; } lv[4*N]; bool operator == (node a, node b){ return ((a.l == b.l) && (a.r == b.r) && (a.val == b.val)); } int n, q; long long S, T, a[N]; node Merge_Node(node a, node b){ node ans; ans.l = a.l, ans.r = b.r; ans.val = a.val + b.val; ans.lazy = 0; if (a.r >= b.l) ans.val += T*abs(a.r - b.l); else ans.val -= S*abs(b.l - a.r); return ans; } void dolazy(int i, int l, int r){ if (lv[i].lazy == 0) return; lv[i].l += lv[i].lazy; lv[i].r += lv[i].lazy; if (l != r){ lv[i*2].lazy += lv[i].lazy; lv[i*2+1].lazy += lv[i].lazy; } lv[i].lazy = 0; } void init(int i, int l, int r){ if (l == r){ lv[i].l = lv[i].r = a[l]; lv[i].val = 0; return; } int mid = (l + r) / 2; init(i*2, l, mid); init(i*2+1, mid+1, r); lv[i] = Merge_Node(lv[i*2], lv[i*2+1]); } void update(int i, int l, int r, int L, int R, long long val){ dolazy(i, l, r); if (L > r || l > R) return; if (L <= l && r <= R) { lv[i].lazy += val; dolazy(i, l, r); return ; } int mid = (l + r) / 2; update(i*2, l, mid, L, R, val); update(i*2+1, mid+1, r, L, R, val); lv[i] = Merge_Node(lv[i*2], lv[i*2+1]); } int main(){ cin >> n >> q >> S >> T; for (int i = 0; i <= n; i++) cin >> a[i]; init(1, 0, n); while (q--){ long long l, r, val; cin >> l >> r >> val; update(1, 0, n, l, r, val); printf("%lld\n", lv[1].val); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...