제출 #163414

#제출 시각아이디문제언어결과실행 시간메모리
163414iefnah06Foehn Phenomena (JOI17_foehn_phenomena)C++11
100 / 100
158 ms13176 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 200010; int N, Q; ll S, T; ll A[MAXN]; ll diff[MAXN]; ll ans; ll get_cost(int p) { if (p > N || diff[p] == 0) { return 0; } else if (diff[p] > 0) { return diff[p] * S; } else { return -diff[p] * T; } } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> N >> Q >> S >> T; S = -S; for (int i = 0; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) { diff[i] = A[i] - A[i-1]; ans += get_cost(i); } for (int q = 0; q < Q; q++) { int l, r; ll x; cin >> l >> r >> x; ans -= get_cost(l) + get_cost(r+1); diff[l] += x; diff[r+1] -= x; ans += get_cost(l) + get_cost(r+1); cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...