| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1306960 | ballbreaker | Foehn Phenomena (JOI17_foehn_phenomena) | C++20 | 233 ms | 7340 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
int a[n + 1];
int d[n + 2] = {};
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];
if (a[i - 1] < a[i]) {
ans -= s * (a[i] - a[i - 1]);
} else {
ans += t * (a[i - 1] - a[i]);
}
}
// cout << ans << endl;
while (q--) {
int l, r, x;
cin >> l >> r >> x;
if (d[l] > 0) {
ans += s * d[l];
} else {
ans += t * d[l];
}
d[l] += x;
if (d[l] > 0) {
ans -= s * d[l];
} else {
ans -= t * d[l];
}
if (r + 1 <= n) {
if (d[r + 1] > 0) {
ans += s * d[r + 1];
} else {
ans += t * d[r + 1];
}
d[r + 1] -= x;
if (d[r + 1] > 0) {
ans -= s * d[r + 1];
} else {
ans -= t * d[r + 1];
}
}
cout << ans << endl;
}
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
