제출 #978733

#제출 시각아이디문제언어결과실행 시간메모리
978733raspyFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
441 ms13136 KiB
#include <iostream> #define int long long using namespace std; int a[200005]; int raz[200005]; int32_t main() { int n, q, s, t; cin >> n >> q >> s >> t; for (int i = 0; i <= n; i++) cin >> a[i]; int rez = 0; for (int i = 0; i < n; i++) { raz[i] = a[i]-a[i+1]; rez += raz[i]*(raz[i] < 0 ? s : t); } while (q--) { int l, r, x; cin >> l >> r >> x; l--; if (x < 0) { // cout << "tets\n"; x = abs(x); if (raz[l] < 0) rez -= raz[l]*s; else rez -= raz[l]*t; raz[l] += x; // cout << l << " " << raz[l] << " " << x << "\n"; if (raz[l] < 0) rez += raz[l]*s; else rez += raz[l]*t; if (r < n) { if (raz[r] < 0) rez -= raz[r]*s; else rez -= raz[r]*t; raz[r] -= x; if (raz[r] < 0) rez += raz[r]*s; else rez += raz[r]*t; } } else if (x > 0) { x = abs(x); if (raz[l] < 0) rez -= raz[l]*s; else rez -= raz[l]*t; raz[l] -= x; if (raz[l] < 0) rez += raz[l]*s; else rez += raz[l]*t; if (r < n) { if (raz[r] < 0) rez -= raz[r]*s; else rez -= raz[r]*t; raz[r] += x; if (raz[r] < 0) rez += raz[r]*s; else rez += raz[r]*t; } } // for (int i = 0; i < n; i++) // cout << raz[i] << " "; // cout << "\n"; cout << rez << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...