Submission #670441

#TimeUsernameProblemLanguageResultExecution timeMemory
670441Sohsoh84Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
139 ms13164 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; ll n, q, s, t, A[MAXN], fen[MAXN], ans; inline void update(int ind, ll val) { for (++ind; ind < MAXN; ind += ind & -ind) fen[ind] += val; } inline void update(int l, int r, ll val) { update(l, val); update(r + 1, -val); } inline ll query(int ind) { ll ans = 0; for (++ind; ind > 0; ind -= ind & -ind) ans += fen[ind]; return ans; } inline ll f(ll x, ll y) { if (x < y) return (x - y) * s; return (x - y) * t; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q >> s >> t >> A[0]; for (int i = 1; i <= n; i++) { cin >> A[i]; ans += f(A[i - 1], A[i]); update(i, i, A[i]); } while (q--) { ll l, r, x; cin >> l >> r >> x; ans -= f(query(l - 1), query(l)); if (r < n) ans -= f(query(r), query(r + 1)); update(l, r, x); ans += f(query(l - 1), query(l)); if (r < n) ans += f(query(r), query(r + 1)); cout << ans << endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...