제출 #757084

#제출 시각아이디문제언어결과실행 시간메모리
757084gun_ganFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
123 ms13080 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 5; ll a[MX], d[MX]; ll N, Q, S, T; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N >> Q >> S >> T; ll ans = 0; S = -S; for(int i = 0; i <= N; i++) { cin >> a[i]; if(!i) continue; d[i] = a[i] - a[i - 1]; if(d[i] > 0) ans += d[i] * S; if(d[i] < 0) ans += -d[i] * T; } for(int j = 1; j <= Q; j++) { ll L, R, X; cin >> L >> R >> X; if(d[L] > 0) ans -= d[L] * S; if(d[L] < 0) ans -= -d[L] * T; d[L] += X; if(d[L] > 0) ans += d[L] * S; if(d[L] < 0) ans += -d[L] * T; if(R + 1 <= N) { if(d[R + 1] > 0) ans -= d[R + 1] * S; if(d[R + 1] < 0) ans -= -d[R + 1] * T; d[R + 1] -= X; if(d[R + 1] > 0) ans += d[R + 1] * S; if(d[R + 1] < 0) ans += -d[R + 1] * T; } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...