제출 #581616

#제출 시각아이디문제언어결과실행 시간메모리
581616colossal_pepeFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
379 ms28012 KiB
#include <iostream> using namespace std; using ll = long long; struct Node { ll t, l, r, lazy; }; const int N = 300005; int n, q; ll a[N], s, t; Node sgt[4 * N]; void init(int u, int l, int r) { if (l == r) { sgt[u].t = 0; sgt[u].l = a[l]; sgt[u].r = a[r]; sgt[u].lazy = 0; } else { int mid = (l + r) / 2; init(2 * u, l, mid); init(2 * u + 1, mid + 1, r); sgt[u].t = sgt[2 * u].t + sgt[2 * u + 1].t + ((sgt[2 * u].r < sgt[2 * u + 1].l ? s : t) * (sgt[2 * u].r - sgt[2 * u + 1].l)); sgt[u].l = sgt[2 * u].l; sgt[u].r = sgt[2 * u + 1].r; sgt[u].lazy = 0; } } void prop(int u) { sgt[2 * u].l += sgt[u].lazy; sgt[2 * u].r += sgt[u].lazy; sgt[2 * u + 1].l += sgt[u].lazy; sgt[2 * u + 1].r += sgt[u].lazy; sgt[2 * u].lazy += sgt[u].lazy; sgt[2 * u + 1].lazy += sgt[u].lazy; sgt[u].lazy = 0; } void update(int u, int l, int r, int L, int R, int x) { if (l != r) prop(u); if (r < L or R < l) return; else if (L <= l and r <= R) { sgt[u].l += x; sgt[u].r += x; sgt[u].lazy += x; } else { int mid = (l + r) / 2; update(2 * u, l, mid, L, R, x); update(2 * u + 1, mid + 1, r, L, R, x); sgt[u].t = sgt[2 * u].t + sgt[2 * u + 1].t + ((sgt[2 * u].r < sgt[2 * u + 1].l ? s : t) * (sgt[2 * u].r - sgt[2 * u + 1].l)); sgt[u].l = sgt[2 * u].l; sgt[u].r = sgt[2 * u + 1].r; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q >> s >> t; for (int i = 0; i <= n; i++) { cin >> a[i]; } init(1, 0, n); while (q--) { int l, r, x; cin >> l >> r >> x; update(1, 0, n, l, r, x); cout << sgt[1].t << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...