| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1354081 | bimmer | Foehn Phenomena (JOI17_foehn_phenomena) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "algo/debug.h"
#endif
using namespace std;
#define int long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int sz = 2e5 + 5, inf = 1e9, mod = 1e9 + 7;
int a[sz], d[sz], n, q, s, t;
int cost(int x){
if (x > 0) return -s * x;
return -t * x;
}
void _(){
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
d[i] = a[i] - a[i - 1];
ans += cost(d[i]);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans -= cost(d[l]);
d[l] += x;
ans += cost(d[l]);
if (r + 1 <= n) {
ans -= cost(d[r + 1]);
d[r + 1] -= x;
ans += cost(d[r + 1]);
}
cout << ans << endl;
}
}
signed main(){
cin.tie(nullptr)->sync_with_stdio(0);
int T = 1;
// cin >> T;
while (T--) _();
}
// By Riyad