# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38043 | MatheusLealV | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 313 ms | 5140 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 inf 200000000000000000LL
#define N 200050
using namespace std;
typedef long long ll;
int n, q;
ll A[N], bit[N], ans, S, T;
void upd(int l, int r, int x)
{
if(1 <= l && l <= n + 1) for(int i = l; i < N; i += (i&-i)) bit[i] += x;
if(1 <= r + 1&& r + 1 <= n + 1) for(int i = r + 1; i < N; i += (i&-i)) bit[i] -= x;
}
ll query(int x)
{
ll aux = 0;
if(x <= 0 || x > n + 1) return inf;
for(int i = x; i > 0; i -= (i&-i)) aux += bit[i];
return aux;
}
int32_t main()
{
scanf("%d %d %lld %lld", &n, &q, &S, &T);
for(int i = 1; i <= n + 1; i++) scanf("%lld", &A[i]), upd(i, i, A[i]);
for(int i = 1; i <= n; i++) ans += (A[i] <= A[i + 1] ? (- A[i + 1] + A[i])*S : (A[i] - A[i + 1])*T);
for(int i = 1; i <= q; i++)
{
int li, ri;
ll xi, dl = 0, dr = 0;
scanf("%d %d %lld", &li, &ri, &xi);
li ++, ri ++;
ll Hl = query(li), Hr = query(ri), H_depois = query(ri + 1), H_antes = query(li - 1);
upd(li, ri, xi);
if(H_antes != inf && H_antes <= Hl) dl -= abs(Hl - H_antes)*S ;
else if(H_antes != inf) dl += abs(Hl - H_antes)*T;
if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ;
else if(H_depois != inf) dr += abs(H_depois - Hr)*T;
ans = ans - dl - dr;
Hl += xi, Hr += xi;
dl = 0, dr = 0;
if(H_antes <= Hl&& H_antes != inf) dl -= abs(Hl - H_antes)*S ;
else if(H_antes != inf) dl += abs(Hl - H_antes)*T;
if(Hr <= H_depois && H_depois != inf) dr -= abs(H_depois - Hr)*S ;
else if(H_depois != inf) dr += abs(H_depois - Hr)*T;
ans += dl + dr;
printf("%lld\n", ans);
}
}
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... |