Submission #852303

#TimeUsernameProblemLanguageResultExecution timeMemory
852303stdfloatFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
467 ms15912 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> a; vector<ll> st, lz; ll bld(int nd, int l, int r) { if (l == r) { return st[nd] = a[l]; } int ch = nd<<1, md = (l + r)>>1; return st[nd] = bld(ch, l, md) + bld(ch + 1, md + 1, r); } void LZ(int nd, int l, int r) { st[nd] += (r - l + 1) * lz[nd]; if (l == r) return; int ch = nd<<1; lz[ch] += lz[nd]; lz[ch + 1] += lz[nd]; lz[nd] = 0; } void upd(int nd, int l, int r, int x, int y, int val) { LZ(nd, l, r); if (r < x || y < l) return; if (x <= l && r <= y) { lz[nd] += val; } else { int ch = nd<<1, md = (l + r)>>1; upd(ch, l, md, x, y, val); upd(ch + 1, md + 1, r, x, y, val); } } ll fnd(int nd, int l, int r, int x) { LZ(nd, l, r); if (l > x || x > r) return 0; if (l == r) return st[nd]; int ch = nd<<1, md = (l + r)>>1; return fnd(ch, l, md, x) + fnd(ch + 1, md + 1, r, x); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q, s, t; cin >> n >> q >> s >> t; a.assign(n + 1, 0); st.assign((n<<2) + 1, 0); lz.assign((n<<2) + 1, 0); for (int i = 0; i <= n; i++) { cin >> a[i]; } bld(1, 0, n); while (q--) { int l, r, x; cin >> l >> r >> x; upd(1, 0, n, l, r, x); if (s == t) { cout << 1LL * s * (fnd(1, 0, n, 0) - fnd(1, 0, n, n)) << '\n'; } else { ll ans = 0; for (int i = 0; i < n; i++) { if (!i) a[i] = fnd(1, 0, n, i); a[i + 1] = fnd(1, 0, n, i + 1); ans += 1LL * (a[i] < a[i + 1] ? s : t) * (a[i] - a[i + 1]); } cout << ans << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...