# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731142 | sleepntsheep | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 17 ms | 3580 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 100005
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);
}
for (long long l, r, x; q--;)
{
long long lo = 0, ro = 0, ln = 0, rn = 0;
scanf("%lld%lld%lld", &l, &r, &x);
if (f.qry(l) < f.qry(l+1)) lo = s * (f.qry(l) - f.qry(l+1)); else lo = t * (f.qry(l) - f.qry(l+1));
if (f.qry(r+1) < f.qry(r+2)) ro = s * (f.qry(r+1) - f.qry(r+2)); else ro = t * (f.qry(r+1) - f.qry(r+2));
f.inc(l+1, x), f.inc(r+2, -x);
if (f.qry(l) < f.qry(l+1)) ln = s * (f.qry(l) - f.qry(l+1)); else ln = t * (f.qry(l) - f.qry(l+1));
if (f.qry(r+1) < f.qry(r+2)) rn = s * (f.qry(r+1) - f.qry(r+2)); else rn = t * (f.qry(r+1) - f.qry(r+2));
g.inc(l+1, ln - lo);
g.inc(r+2, rn - ro);
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... |