This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define Task "DATA"
#define ll long long
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
const int N = 1e6 + 6;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int n, q;
ll s, t;
ll a[N], fen[N];
void update(int idx, int val) {
while (idx < N) {
fen[idx] += val;
idx += (idx & -idx);
}
}
ll get(int idx) {
ll res = 0;
while (idx >= 1) {
res += fen[idx];
idx -= (idx & -idx);
}
return res;
}
ll cost(int x, int y) {
return (y > x ? -s * (y - x) : t * (x - y));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(Task".INP", "r")) {
freopen(Task".INP", "r", stdin);
freopen(Task".OUT", "w", stdout);
}
cin >> n >> q >> s >> t;
FOR(i, 0, n) cin >> a[i];
ll ans = 0;
FOR(i, 1, n) {
update(i, a[i]);
update(i + 1, -a[i]);
ans += cost(a[i - 1], a[i]);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans -= cost(get(l - 1), get(l));
update(l, x);
ans += cost(get(l - 1), get(l));
if (r + 1 <= n) {
ans -= cost(get(r), get(r + 1));
update(r + 1, -x);
ans += cost(get(r), get(r + 1));
}
cout << ans << "\n";
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen(Task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | 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... |