#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define REV(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
using namespace std;
int n, m, s, t;
#define MAXN 200005
int a[MAXN];
int bit[MAXN];
void upd(int p, int val) {
for (; p <= n; p += p & -p) bit[p] += val;
}
void updrange(int u, int v, int val) {
upd(u, +val);
upd(v + 1, -val);
}
int get(int x){
int res = 0;
while (x) res += bit[x], x -= x & -x;
return res;
}
int cost(int x, int delta) {
int f1 = a[x] + get(x);
int f2 = a[x + 1] + get(x + 1);
if (f1 < f2) return (f1 - f2) * s * delta;
return (f1 - f2) * t * delta;
}
void solve(){
cin >> n >> m >> s >> t;
int res = 0;
FOR(i, 0, n) cin >> a[i];
FOR(i, 0, n - 1) res += cost(i, 1);
FOR(i, 1, m){
int l, r, v; cin >> l >> r >> v;
if (l - 1 >= 0) res += cost(l - 1, -1);
if (r + 1 <= n) res += cost(r, -1);
updrange(l, r, v);
if (l - 1 >= 0) res += cost(l - 1, 1);
if (r + 1 <= n) res += cost(r, 1);
cout << res << '\n';
}
}
#define task "test"
int32_t main(){
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'int32_t main()':
foehn_phenomena.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |