# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731147 | sleepntsheep | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 200 ms | 7552 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 <stdio.h>
#include <algorithm>
template <class T>
struct BIT
{
int n; T *a;
BIT(int m) : n(1+m), a(new T[1+m]) {}
~BIT() { delete []a; }
void inc(int p, T x) { for (++p; p <= n; p+=p&-p) a[p] += x; }
auto qry(int p, T z = 0) { for (++p; p; p-=p&-p) z+=a[p]; return z;}
};
using ll = long long;
#define N 402005
int n, q, s, t;
BIT<ll> f(N), g(N);
int main()
{
scanf("%d%d%d%d", &n, &q, &s, &t);
for (ll i = 0, x; i <= n; i++)
scanf("%lld", &x), f.inc(i, x), f.inc(i+1, -x);
for (int i = 1; i <= n; i++)
{
auto d = -f.qry(i) + f.qry(i-1);
g.inc(i, (d < 0 ? s : t) * d);
}
auto upd = [&](int p, ll x){
auto d = f.qry(p-1) - f.qry(p);
g.inc(p, -(d < 0 ? s : t) * d);
f.inc(p, x);
d = f.qry(p-1) - f.qry(p);
g.inc(p, (d < 0 ? s : t) * d);
};
for (ll l, r, x; q--;)
{
scanf("%lld%lld%lld", &l, &r, &x);
upd(l, x);
upd(r+1, -x);
printf("%lld\n", g.qry(n));
}
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... |