# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731144 | sleepntsheep | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 187 ms | 13016 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;}
void updmax(int p, T x) { for (;p<n; p+=p&-p) a[p]=std::max(x,a[p]);}
T qrymax(int p, T z) { for (;p; p-=p&-p) z=std::max(z,a[p]); return z;}
};
#define N 402005
long long n, q, s, t, a[N];
BIT<long long> f(N), g(N);
int main()
{
scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
for (int i = 0; i <= n; i++) scanf("%lld", a+i), f.inc(i+1, a[i]), f.inc(i+2, -a[i]);
for (int i = 1; i <= n; i++)
{
auto d = -f.qry(i+1) + f.qry(i);
if (d < 0) g.inc(i+1, s * d);
else g.inc(i+1, t * d);
}
auto upd = [&](int p, long long x){
long long old = 0, aft = 0;
auto d = f.qry(p-1) - f.qry(p);
old = (d < 0 ? s : t) * d;
f.inc(p, x);
d = f.qry(p-1) - f.qry(p);
aft = (d < 0 ? s : t) * d;
g.inc(p, aft - old);
};
for (long long 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... |