# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
116644 | roseanne_pcy | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 203 ms | 13048 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.
//I don't want a lot for Christmas
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vvi vector< vi >
#define vii vector< ii >
#define mp make_pair
#define pb push_back
const int maxn = 2e5+5;
ll ft[maxn];
int n;
ll a[maxn];
void update(int x, int dx)
{
for(; x<= n; x+=x&(-x)) ft[x] += dx;
}
ll sum(int x)
{
ll res = 0;
for(; x; x -= x&(-x)) res += ft[x];
return res;
}
ll ask(int a, int b)
{
return sum(a);
}
void add(int a, int b, int dx)
{
update(a, dx);
update(b+1, -dx);
}
int main()
{
//#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
int q, s, t; scanf("%d %d %d %d", &n, &q, &s, &t);
for(int i = 0; i<= n; i++) scanf("%lld", a+i);
ll now = 0;
for(int i = 0; i+1<= n; i++)
{
int dx = abs(a[i]-a[i+1]);
if(a[i]< a[i+1])
{
now -= 1LL*s*dx;
}
else now += 1LL*t*dx;
}
for(int i = 1; i<= n; i++)
{
add(i, i, (int)a[i]);
}
while(q--)
{
//printf("%d\n", q);
int L, R, x; scanf("%d %d %d", &L, &R, &x);
ll aL = ask(L-1, L-1);
ll aLp = ask(L, L);
//printf("*%d %d\n", aL, aLp);
ll dx = abs(aL-aLp);
if(aL< aLp) now += 1LL*s*dx;
else now -= 1LL*t*dx;
aLp += x;
dx = abs(aL-aLp);
if(aL< aLp) now -= 1LL*s*dx;
else now += 1LL*t*dx;
//printf("temp %lld\n", now);
if(R == n)
{
add(L, R, x);
printf("%lld\n", now);
continue;
}
aL = ask(R, R);
aLp = ask(R+1, R+1);
//printf("**%d %d\n", aL, aLp);
dx = abs(aL-aLp);
if(aL< aLp) now += 1LL*s*dx;
else now -= 1LL*t*dx;
aL += x;
dx = abs(aL-aLp);
if(aL< aLp) now -= 1LL*s*dx;
else now += 1LL*t*dx;
add(L, R, x);
printf("%lld\n", now);
}
}
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... |