Submission #143314

#TimeUsernameProblemLanguageResultExecution timeMemory
143314osaaateiasavtnlFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
227 ms7812 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcount const int N = 2e5 + 7; int a[N], f[N]; void upd(int i, int x) { for (; i < N; i |= i + 1) f[i] += x; } int get(int i) { int ans = 0; for (; i >= 0; i &= i + 1, --i) ans += f[i]; return ans; } int n, q, s, t; int getv(int i) { if (i == n) return 0; a[i] = get(i); a[i + 1] = get(i + 1); if (a[i] < a[i + 1]) return - s * abs(a[i] - a[i + 1]); else return t * abs(a[i] - a[i + 1]); } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n >> q >> s >> t; for (int i = 0; i <= n; ++i) { cin >> a[i]; upd(i, a[i]); upd(i + 1, -a[i]); } int ans = 0; for (int i = 0; i < n; ++i) ans += getv(i); while (q--) { int l, r, x; cin >> l >> r >> x; ans -= getv(l - 1); ans -= getv(r); upd(l, x); upd(r + 1, -x); ans += getv(l - 1); ans += getv(r); cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...