제출 #751176

#제출 시각아이디문제언어결과실행 시간메모리
751176vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
337 ms8448 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long ll N, Q, S, T; ll a[200100], b[200100]; ll L, R, X, ans; int main () { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> N >> Q >> S >> T; cin >> a[0]; for(int i=1; i<=N; i++) { cin >> a[i]; b[i] = a[i]-a[i-1]; ans += (b[i] > 0)?(-S*b[i]):(T*(-b[i])); } //cout << ans << endl; for(int i=1; i<=Q; i++) { cin >> L >> R >> X; ans -= (b[L] > 0)?(-S*b[L]):(T*(-b[L])); b[L]+=X; ans += (b[L] > 0)?(-S*b[L]):(T*(-b[L])); if (R<N) { ans -= (b[R+1] > 0)?(-S*b[R+1]):(T*(-b[R+1])); b[R+1]-=X; ans += (b[R+1] > 0)?(-S*b[R+1]):(T*(-b[R+1])); } cout << ans << endl; } } // b[i] = a[i]-a[i-1] // jika b[i]>0, temp-=S // jika b[i]<=0, temp+=T // jika A[L...R] += X, maka, b[L]+=X dan b[R+1]-=X
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...