This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
using namespace std;
template<typename T> void uin(T &a, T b) {
if (b < a) {
a = b;
}
}
template<typename T> void uax(T &a, T b) {
if (b > a) {
a = b;
}
}
#define int long long
#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228
const int N = 200 * 1000 + 228;
int n, q, s, t;
int a[N];
struct node
{
int sum, mod;
int l, r;
node() {sum = mod = l = r = 0;}
};
vector<node> d;
void build(int l, int r, int v = 1) {
d[v].l = l, d[v].r = r;
if (l == r) d[v].sum = a[l];
else {
int m = (l + r) >> 1;
build(l, m, v << 1), build(m + 1, r, v << 1 | 1);
d[v].sum = d[v << 1].sum + d[v << 1 | 1].sum;
}
}
int gets(int v) { return d[v].sum + d[v].mod * (d[v].r - d[v].l + 1); }
void push(int v) {
d[v << 1].mod += d[v].mod, d[v << 1 | 1].mod += d[v].mod, d[v].mod = 0;
d[v].sum = gets(v << 1) + gets(v << 1 | 1);
}
void update(int l, int r, int x, int v = 1) {
if (l > r || d[v].l > r || d[v].r < l) return;
if (l <= d[v].l && d[v].r <= r) d[v].mod += x;
else {
push(v);
update(l, r, x, v << 1), update(l, r, x, v << 1 | 1);
d[v].sum = gets(v << 1) + gets(v << 1 | 1);
}
}
int get(int i, int v = 1) {
if (d[v].l == d[v].r) return gets(v);
push(v);
if (i <= (d[v].l + d[v].r) >> 1) return get(i, v << 1);
return get(i, v << 1 | 1);
}
void init(int n) {
int ss = 1; while (ss < n) ss <<= 1;
ss <<= 1; d.resize(ss + 3, node()); build(1, n);
}
int res = 0;
int f(int i) {
if (!i || i > n + 1) return 0;
int A = get(i - 1), B = get(i);
if (A < B) return -(B - A) * s;
return (A - B) * t;
}
ghost main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q >> s >> t;
for (int i = 1; i <= n + 1; ++i) cin >> a[i];
for (int i = 2; i <= n + 1; ++i) {
if (a[i - 1] < a[i]) res -= s * (a[i] - a[i - 1]);
else res += t * (a[i - 1] - a[i]);
}
init(n + 1);
while (q--) {
int l, r, x;
cin >> l >> r >> x;
++l, ++r;
res -= f(l);
res -= f(r + 1);
update(l, r, x);
res += f(l);
res += f(r + 1);
cout << res << '\n';
}
return 0;
} // kek ;
// Ого! Кажетсья это $#@!
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |