Submission #850267

#TimeUsernameProblemLanguageResultExecution timeMemory
850267PekibanFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
379 ms15184 KiB
#include <bits/stdc++.h> using namespace std; int _n; const int mxN = 2e5+2; long long st[4*mxN]; void update(int k, int x, int i = 1, int l = 0, int r = _n-1) { if (l == r) { st[i] += x; return; } int mid = (l + r)/2; if (k <= mid) { update(k, x, 2*i, l, mid); } else { update(k, x, 2*i+1, mid+1, r); } st[i] = st[2*i]+st[2*i+1]; } long long query(int l, int r, int i = 1, int l2 = 0, int r2 = _n-1) { if (l <= l2 && r2 <= r) { return st[i]; } int mid = (l2 + r2)/2; long long s = 0; if (l <= mid) { s += query(l, r, 2*i, l2, mid); } if (mid+1 <= r) { s += query(l, r, 2*i+1, mid+1, r2); } return s; } int main() { ios::sync_with_stdio(0); cin.tie(0); long long n, q, s, t; cin >> n >> q >> s >> t; _n = n+1; vector<int> a(n+1); long long sum = 0; for (int i = 0; i <= n; ++i) { cin >> a[i]; if (i) sum += (a[i] > a[i-1] ? -s*(a[i]-a[i-1]) : t*(a[i-1]-a[i])); } update(0, a[0]); for (int i = 1; i <= n; ++i) { update(i, a[i]-a[i-1]); } while (q--) { int l, r, x; cin >> l >> r >> x; const long long lo1 = query(0, l-1), lo2 = query(0, l); update(l, x); sum -= (lo2 > lo1 ? -s*(lo2-lo1) : t*(lo1-lo2)); if (r != n) { const long long ro1 = query(0, r), ro2 = query(0, r+1); sum-=(ro2 > ro1 ? -s*(ro2-ro1) : t*(ro1-ro2)); update(r+1, -x); } const long long l1 = query(0, l-1), l2 = query(0, l); if (r != n) { const long long r2 = query(0, r+1), r1 = query(0, r); sum+=(r2 > r1 ? -s*(r2-r1) : t*(r1-r2)); } sum+=(l2 > l1 ? -s*(l2-l1) : t*(l1-l2)); cout << sum << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...