제출 #787899

#제출 시각아이디문제언어결과실행 시간메모리
787899acatmeowmeowFoehn Phenomena (JOI17_foehn_phenomena)C++11
100 / 100
279 ms15616 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5; int n, q, s, t, arr[N + 5], tree[4*N + 5]; void update(int v, int tl, int tr, int k, int x) { if (tl == tr) tree[v] += x; else { int tm = (tl + tr)/2; if (k <= tm) update(v*2, tl, tm, k, x); else update(v*2 + 1, tm + 1, tr, k, x); tree[v] = tree[v*2] + tree[v*2 + 1]; } } int query(int v, int tl, int tr, int l, int r) { if (l > r) return 0; else if (tl == l && tr == r) return tree[v]; else { int tm = (tl + tr)/2; return query(v*2, tl, tm, l, min(tm, r)) + query(v*2 + 1, tm + 1, tr, max(l, tm + 1), r); } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> q >> s >> t; for (int i = 0; i <= n; i++) { cin >> arr[i]; update(1, 0, n + 1, i, arr[i]); update(1, 0, n + 1, i + 1, -arr[i]); } int ans = 0; for (int i = 0; i < n; i++) { if (arr[i] < arr[i + 1]) ans -= s*abs(arr[i] - arr[i + 1]); else ans += t*abs(arr[i] - arr[i + 1]); } while (q--) { int l, r, x; cin >> l >> r >> x; int pl = query(1, 0, n + 1, 0, l - 1), curl = query(1, 0, n + 1, 0, l); if (pl < curl) ans += s*abs(pl - curl); else ans -= t*abs(pl - curl); int nr = query(1, 0, n + 1, 0, r + 1), curr = query(1, 0, n + 1, 0, r); if (r < n && curr < nr) ans += s*abs(nr - curr); else if (r < n) ans -= t*abs(nr - curr); update(1, 0, n + 1, l, x); update(1, 0, n + 1, r + 1, -x); curl += x; if (pl < curl) ans -= s*abs(pl - curl); else ans += t*abs(pl - curl); curr += x; if (r < n && curr < nr) ans -= s*abs(curr - nr); else if (r < n) ans += t*abs(curr - nr); cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...