Submission #129298

#TimeUsernameProblemLanguageResultExecution timeMemory
129298souhhcongFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
691 ms7396 KiB
#include <iostream> using namespace std; #define int long long const int N = 2e5+5; int n, q, s, t; int l, r, val, sum_neg, sum_pos; int a[N], diff[N]; void update(int i, int val) { if (i < 0 || i >= n) return; if (diff[i] > 0 && diff[i] + val >= 0) { sum_pos += val; } else if (diff[i] > 0 && diff[i] + val < 0) { sum_pos -= diff[i]; sum_neg += (diff[i]+val); } else if (diff[i] <= 0 && diff[i]+val >= 0) { sum_neg -= diff[i]; sum_pos += diff[i]+val; } else if (diff[i] <= 0 && diff[i] + val < 0) { sum_neg += val; } diff[i] += val; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> q >> s >> t; for (int i = 0; i <= n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { diff[i] = a[i] - a[i+1]; if (diff[i] < 0) sum_neg += diff[i]; else sum_pos += diff[i]; } while(q--) { cin >> l >> r >> val; update(l-1,-val); update(r,val); cout << sum_neg*s + sum_pos*t << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...