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