# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404119 | radaiosm7 | Foehn Phenomena (JOI17_foehn_phenomena) | C++98 | 173 ms | 10436 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>
using namespace std;
int n, q, i, l, r;
long long s, t, c, ans, curl1, curl2, curr1, curr2;
long long alt[200005];
long long fen[200005];
void add(long long val, int indx) {
for (++indx; indx <= n; indx += (indx&(-indx))) {
fen[indx] += val;
}
}
void addlr(long long val, int l, int r) {
add(val, l);
add(-val, r+1);
}
long long point(int indx) {
long long res = 0LL;
for (++indx; indx > 0; indx -= (indx & (-indx))) {
res += fen[indx];
}
return res;
}
int main() {
scanf("%d%d%lld%lld", &n, &q, &s, &t);
ans = 0LL;
t *= -1LL;
scanf("%lld", &alt[0]);
for (i=1; i <= n; ++i) {
scanf("%lld", &alt[i]);
addlr(alt[i], i, i);
if (alt[i] > alt[i-1]) {
ans += (alt[i]-alt[i-1])*s;
}
else {
ans += (alt[i-1]-alt[i])*t;
}
}
while (q--) {
scanf("%d%d%lld", &l, &r, &c);
curl1 = point(l-1);
curl2 = point(l);
if (curl2 > curl1) {
ans -= (curl2-curl1)*s;
}
else {
ans -= (curl1-curl2)*t;
}
if (r+1 <= n) {
curr2 = point(r+1);
curr1 = point(r);
if (curr2 > curr1) {
ans -= (curr2-curr1)*s;
}
else {
ans -= (curr1-curr2)*t;
}
}
addlr(c, l, r);
curl2 = point(l);
if (curl2 > curl1) {
ans += (curl2-curl1)*s;
}
else {
ans += (curl1-curl2)*t;
}
if (r+1 <= n) {
curr1 = point(r);
if (curr2 > curr1) {
ans += (curr2-curr1)*s;
}
else {
ans += (curr1-curr2)*t;
}
}
printf("%lld\n", ans);
}
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... |