# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
114105 | alexpetrescu | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 488 ms | 14924 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 <cstdio>
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout
#define ll long long
#define MAXN 200009
#define MAXP 530000
int n, s, t, left, right, val, v[MAXN];
ll aint[MAXP];
void update(int p, int st, int dr) {
if (left <= st && dr <= right)
aint[p] += val;
else {
int m = (st + dr) / 2;
if (left <= m) update(2 * p, st, m);
if (m < right) update(2 * p + 1, m + 1, dr);
}
}
inline ll query(int poz) {
if (poz > n)
poz = n;
int p = 1, st = 0, dr = n;
ll ans = v[poz];
while (st < dr) {
ans += aint[p];
int m = (st + dr) / 2;
if (poz <= m)
dr = m, p = 2 * p;
else
st = m + 1, p = 2 * p + 1;
}
return ans + aint[p];
}
inline ll cost(ll a, ll b) {
if (a < b)
return (a - b) * s;
else
return (a - b) * t;
}
inline ll calc(int l, int r) {
return cost(query(l - 1), query(l)) + cost(query(r), query(r + 1));
}
int main() {
int q;
fscanf(fin, "%d%d%d%d", &n, &q, &s, &t);
ll ans = 0;
for (int i = 0; i <= n; i++) {
fscanf(fin, "%d", &v[i]);
ans += cost(v[i - 1], v[i]);
}
for (int i = 1; i <= q; i++) {
fscanf(fin, "%d%d%d", &left, &right, &val);
ans -= calc(left, right);
update(1, 0, n);
ans += calc(left, right);
fprintf(fout, "%lld\n", ans);
}
fclose(fin);
fclose(fout);
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... |