Submission #384225

#TimeUsernameProblemLanguageResultExecution timeMemory
384225aryan12Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
158 ms13164 KiB
#include <bits/stdc++.h> using namespace std; #define int long long void Solve() { int n, q, dec, inc; cin >> n >> q >> dec >> inc; int a[n + 1], diff[n + 1]; for(int i = 0; i <= n; i++) { cin >> a[i]; diff[i] = 0; } int curAns = 0; for(int i = 1; i <= n; i++) { diff[i] = a[i] - a[i - 1]; if(a[i] <= a[i - 1]) { curAns += inc * (a[i - 1] - a[i]); } else { curAns -= dec * (a[i] - a[i - 1]); } } for(int i = 1; i <= q; i++) { int l, r, x; cin >> l >> r >> x; curAns -= (diff[l] <= 0) ? (inc * (-diff[l])) : -(dec * diff[l]); diff[l] += x; curAns += (diff[l] <= 0) ? (inc * (-diff[l])) : -(dec * diff[l]); if(r != n) { curAns -= (diff[r + 1] <= 0) ? (inc * (-diff[r + 1])) : -(dec * diff[r + 1]); diff[r + 1] -= x; curAns += (diff[r + 1] <= 0) ? (inc * (-diff[r + 1])) : -(dec * diff[r + 1]); } cout << curAns << "\n"; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...