Submission #403493

#TimeUsernameProblemLanguageResultExecution timeMemory
403493Drew_Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
200 ms11536 KiB
#include <iostream> using namespace std; #define ll long long const int MAX = 2e5 + 7; ll bit[MAX]; inline void add(int x, ll val) { for (int i = x; i < MAX; i += (i & -i)) bit[i] += val; } inline ll sum(int x) { ll res = 0; for (int i = x; i > 0; i -= (i & -i)) res += bit[i]; return res; } ll n, q, s, t, val = 0; inline void in(int i) { ll x = sum(i) - sum(i-1); if (x >= 0) val -= s*x; else val -= t*x; } inline void out(int i) { ll x = sum(i) - sum(i-1); if (x >= 0) val += s*x; else val += t*x; } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q >> s >> t; for (int i = 0; i <= n; ++i) { ll x; cin >> x; if (i) { add(i, x - sum(i-1)); in(i); } } while (q--) { int l, r, k; cin >> l >> r >> k; out(l); if (r < n) out(r+1); add(l, k); add(r+1, -k); in(l); if (r < n) in(r+1); cout << val << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...