# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
68214 | almasalmas | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 797 ms | 7628 KiB |
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>
#define int long long
using namespace std;
int a[200001];
int d[200001];
main () {
int n, q, s, t;
cin >> n >> q >> s >> t;
for (int i = 0;i <= n;i ++) cin >> a[i];
int cur = 0;
for (int i = 1;i <= n;i ++) {
int len = abs (a[i] - a[i - 1]);
if (a[i] > a[i - 1]) {
cur -= len * s;
}
else cur += len * t;
}
// cout << cur << endl;
while (q --) {
int l, r, x;
cin >> l >> r >> x;
if (r != n) {
int X = a[r];
a[r] += d[r];
if (a[r] < a[r + 1]) {
cur += s * (a[r + 1] - a[r]);
}
else cur -= t * (a[r] - a[r + 1]);
d[r] += x;
a[r] += x;
if (a[r] < a[r + 1]) {
cur -= s * (a[r + 1] - a[r]);
}
else cur += t * (a[r] - a[r + 1]);
a[r] = X;
}
// cout << cur << endl;
int X = a[l - 1];
a[l - 1] += d[l - 1];
if (a[l - 1] < a[l]) {
cur += s * (a[l] - a[l - 1]);
}
else cur -= t * (a[l - 1] - a[l]);
d[l - 1] -= x;
a[l - 1] -= x;
if (a[l - 1] < a[l]) {
cur -= s * (a[l] - a[l - 1]);
}
else cur += t * (a[l - 1] - a[l]);
a[l - 1] = X;
cout << cur << endl;
}
return 0;
}
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... |