Problem:
Foehn Phenomena
In the Kingdom of IOI, the wind always blows from sea to land. There are $N + 1$ spots numbered from $0$ to $N$. The wind from Spot $0$ to Spot $N$ in order. Mr. JOI has a house at Spot $N$. The altitude of Spot $0$ is $A_0 = 0$, and the altitude of Spot $i$ ($1 \leq i \leq N$) is $A_i$.
The wind blows on the surface of the ground. The temperature of the wind changes according to the change of the altitude. The temperature of the wind at Spot $0$, which is closest to the sea, is $0$ degree. For each $i$ ($0 \leq i \leq N - 1$), the change of the temperature of the wind from Spot $i$ to Spot $i + 1$ depends only on the values of $A_i$ and $A_{i+1}$ in the following way:
If $A_i < A_{i+1}$, the temperature of the wind decreases by $S$ degrees per altitude.
If $A_i \geq A_{i+1}$, the temperature of the wind increases by $T$ degrees per altitude.
The tectonic movement is active in the land of the Kingdom of IOI. You have the data of tectonic movements for $Q$ days. In the $j$-th ($1 \leq j \leq Q$) day, the change of the altitude of Spot $k$ for $L_j \leq k \leq R_j$ ($1 \leq L_j \leq R_j \leq N$) is described by $X_j$. If $X_j$ is not negative, the altitude increases by $X_j$. If $X_j$ is negative, the altitude decreases by $|X_j|$.
Your task is to calculate the temperature of the wind at the house of Mr. JOI after each tectonic movement.
Task
Given the data of tectonic movements, write a program which calculates, for each $j$ ($1 \leq j \leq Q$), the temperature of the wind at the house of Mr. JOI after the tectonic movement on the $j$-th day.
Input
Read the following data from the standard input.
The first line of input contains four space separated integers $N$, $Q$, $S$, $T$. This means there is a house of Mr. JOI at Spot $N$, there are $Q$ tectonic movements, the temperature of the wind decreases by $S$ degrees per altitude if the altitude increases, and the temperature of the wind increases by $T$ degrees per altitude if the altitude decreases.
The $i$-th line ($1 \leq i \leq N +1$) of the following $N +1$ lines contains an integer $A_{i-1}$, which is the initial altitude at Spot ($i - 1$) before tectonic movements.
The $j$-th line ($1 \leq j \leq Q$) of the following $Q$ lines contains three space separated integers $L_j$, $R_j$, $X_j$. This means, for the tectonic movement on the $j$-th day, the change of the altitude at the spots from $L_j$ to $R_j$ is described by $X_j$.
Output
Write $Q$ lines to the standard output. The $j$-th line ($1 \leq j \leq Q$) of output contains the temperature of the wind
at the house of Mr. JOI after the tectonic movement on the $j$-th day.
Constraints
All input data satisfy the following conditions.
$1 \leq N \leq 200 000．$
$1 \leq Q \leq 200 000．$
$1 \leq S \leq 1 000 000．$
$1 \leq T \leq 1 000 000．$
$A_0 = 0．$
$-1 000 000 \leq A_i \leq 1 000 000 (1 \leq i \leq N)．$
$1 \leq L_j \leq R_j \leq N (1 \leq j \leq Q)．$
$ -1 000 000 \leq X_j \leq 1 000 000 (1 \leq j \leq Q)．$
Sample Input and Output
S
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define MAXN 200005
#define LIMIT 1500
#define LOGN 20
#define ll long long
#define pb push_back
#define ld long double
using namespace std;
ll n,q,s,t;
ll arr[MAXN],tree[4*MAXN],lazy[4*MAXN];
bool de[MAXN];
inline void checkLazy(int pos, int l, int r){
	if(lazy[pos]==0)return;
	tree[pos]+=lazy[pos];
	if(l!=r){
		lazy[2*pos]+=lazy[pos];
		lazy[2*pos+1]+=lazy[pos];
	}
	lazy[pos]=0;
}
void upd(int pos, int l, int r, int ql, int qr, ll val){
	//cout<<pos<<' '<<l<<' '<<r<<' '<<ql<<' '<<qr<<' '<<val<<endl;
	checkLazy(pos,l,r);
	if(l>qr||r<ql)return;
	if(ql<=l&&r<=qr){
		lazy[pos]+=val;
		checkLazy(pos,l,r);
		return;
	}
	int mid=(l+r)/2;
	upd(2*pos,l,mid,ql,qr,val);
	upd(2*pos+1,mid+1,r,ql,qr,val);
}
ll query(int pos, int l, int r, int x){
	checkLazy(pos,l,r);
	if(l==r)return tree[pos];
	int mid=(l+r)/2;
	if(x<=mid)return query(2*pos,l,mid,x);
	else return query(2*pos+1,mid+1,r,x);
}
ll alt=0;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>q>>s>>t;
	n++;
	rep(i,n)cin>>arr[i];
	rep(i,n-1){
		if(arr[i]<arr[i+1])alt-=(arr[i+1]-arr[i])*s;
		else alt-=(arr[i+1]-arr[i])*t;
	}
	//cout<<alt<<endl;
	int l,r;
	ll x;
	rep(i,q){
		cin>>l>>r>>x;
		ll tmp1,tmp2;
		if(l!=0){
			tmp1=arr[l-1]+query(1,0,n-1,l-1),tmp2=arr[l]+query(1,0,n-1,l);
			if(tmp1<tmp2){
				alt+=(tmp2-tmp1)*s;
			}else{
				alt+=(tmp2-tmp1)*t;
			}
		}
		if(r!=n-1){
			tmp1=arr[r]+query(1,0,n-1,r),tmp2=arr[r+1]+query(1,0,n-1,r+1);
			if(tmp1<tmp2){
				alt+=(tmp2-tmp1)*s;
			}else{
				alt+=(tmp2-tmp1)*t;
			}
		}
		upd(1,0,n-1,l,r,x);
		if(l!=0){
			tmp1=arr[l-1]+query(1,0,n-1,l-1),tmp2=arr[l]+query(1,0,n-1,l);
			if(tmp1<tmp2){
				alt-=(tmp2-tmp1)*s;
			}else{
				alt-=(tmp2-tmp1)*t;
			}
		}
		if(r!=n-1){
			tmp1=arr[r]+query(1,0,n-1,r),tmp2=arr[r+1]+query(1,0,n-1,r+1);
			if(tmp1<tmp2){
				alt-=(tmp2-tmp1)*s;
			}else{
				alt-=(tmp2-tmp1)*t;
			}
		}
		cout<<alt<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 17112
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 200020;
ll tree[4*MAX], lazy[4*MAX];
ll H, a[MAX];
int n, q, s, t, d;
void build(int idx, int l, int r){
	if (l==r){
		tree[idx] = a[l];
		return;
	}
	int mid = (l+r)/2;
	build(2*idx, l, mid);
	build(2*idx+1, mid+1, r);
	return;
}
void propagate(int idx, int l, int r){
	if (lazy[idx]==0) return;
	tree[idx] += lazy[idx]*(r-l+1);
	if (l!=r){
		lazy[idx*2] += lazy[idx];
		lazy[idx*2+1] += lazy[idx];
	}
	lazy[idx] = 0;
	return;
}
void update(int idx, int l, int r, int a, int b, ll val){
	propagate(idx, l, r);
	if (r < a || l > b) return;
	if (l >= a && r <= b){
		lazy[idx] += val;
		propagate(idx, l, r);
		return;
	}
	int mid = (l+r)/2;
	update(idx*2, l, mid, a, b, val);
	update(idx*2+1, mid+1, r, a, b, val);
	tree[idx] = tree[idx*2] + tree[idx*2+1];
	
}
ll query(int idx, int l, int r, int x){
	if (x==0) return 0;
	if (x == n+1) return 0;
	propagate(idx, l, r);
	if (l==x && r==x){
		return tree[idx];
	}
	if (l > x || r < x) return 0;
	int mid = (l+r)/2;
	return query(idx*2, l, mid, x)+query(idx*2+1, mid+1, r, x);
	
}
ll sel(ll a, ll b){
	if (b> a){
		return -1*(b-a)*(ll)s;
	}
	return (a-b)*(ll)t;
}
int main(){
	scanf("%d%d%d%d", &n, &q, &s, &t);
	scanf("%d", &d);
	for (int i= 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	build(1, 1, n);
	int now = 0;
	for (int i = 1; i<= n; i++){
		H += sel(now, a[i]);
		now = a[i];
	}
	int x, l, r;
	while(q--){
		scanf("%d%d%d", &l, &r, &x);
		int p1 = query(1, 1, n, l-1);
		int p2 = query(1, 1, n, l);
		int q1 = query(1, 1, n, r);
		int q2 = query(1, 1, n, r+1);
		update(1, 1, n, l, r, x);
	//	printf("%d %d %d %d\n", p1, p2, q1, q2);
		ll F = sel(p1, p2+x) - sel(p1, p2 );
		if (r!=n) F += sel(q1+x, q2) - sel(q1, q2);
		H += F;
		cout << H << "\n";
		
		
	}
}
accuracy: 0.4909090909090909
time_ms: 250
memory_kb: 15780
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long

int get_delta(int diff, int s, int t) {
    if (diff > 0)
        return -diff * s;
    else
        return -diff * t;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q, s, t;
    cin >> n >> q >> s >> t;
    vector<int> arr(n + 1);
    for (auto &el : arr)
        cin >> el;
    vector<int> diff(n);

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        diff[i] = arr[i + 1] - arr[i];
        ans += get_delta(diff[i], s, t);
    }
    for (int qq = 0; qq < q; ++qq) {
        int l, r, x;
        cin >> l >> r >> x;
        ans -= get_delta(diff[l - 1], s, t);
        diff[l - 1] += x;
        ans += get_delta(diff[l - 1], s, t);
        if (r < n) {
            ans -= get_delta(diff[r], s, t);
            diff[r] -= x;
            ans += get_delta(diff[r], s, t);
        }
        cout << ans << '\n';
    }
}
accuracy: 1
time_ms: 60
memory_kb: 6240
final_rank: 4

code_snippet: #include <bits/stdc++.h>

#define el "\n"
#define fu(i, a, b) for (long long i = a; i <= b; ++i)
#define fd(i, a, b) for (long long i = a; i >= b; --i)
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define sz(v) (ll)(v).size()
#define mask(i) (1LL << (i))
#define bit(x, i) ((x) >> (i) & 1)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll Rand(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r) (rng);
}

ll last(ll msk)     {return msk & (-msk);}
ll pop_cnt(ll msk)  {return __builtin_popcountll(msk);}
ll ctz(ll msk)      {return __builtin_ctzll(msk);}
ll lg(ll msk)       {return 63 - __builtin_clzll(msk);}

template<class T1, class T2> bool minimize(T1 &a, T2 b) {
    return a > b ? a = b, 1 : 0;
}

template<class T1, class T2> bool maximize(T1 &a, T2 b) {
    return a < b ? a = b, 1 : 0;
}

template<class T> void print(T a) {
    for (auto x : a) cout << x << " ";
    cout << el;
}

template<class T> void compress(T &a) {
    sort(all(a));
    a.resize(unique(all(a)) - a.begin());
}

const long long N = 1e6 + 27, lim = 32, inf = 2e18, bl = 320, base = 311, mod = 1e9 + 7;

struct SegmentTree {
    ll n;
    vector<ll> t, lazy;

    SegmentTree(ll _n) {
        n = _n;
        t.resize(4 * n + 27);
        lazy.resize(4 * n + 27);
    }

    void down(ll id, ll l, ll r) {
        if (!lazy[id]) return;
        ll mid = (l + r) / 2;
        t[id * 2] += lazy[id] * (mid - l + 1);
        lazy[id * 2] += lazy[id];
        t[id * 2 + 1] += lazy[id] * (r - mid);
        lazy[id * 2 + 1] += lazy[id];
        lazy[id] = 0;
    }

    void update(ll id, ll l, ll r, ll u, ll v, ll c) {
        if (r < u || l > v) return;
        if (u <= l && r <= v) {
            t[id] += c * (r - l + 1);
            lazy[id] += c;
            return;
        }
        down(id, l, r);
        ll mid = (l + r) / 2;
        update(id * 2, l, mid, u, v, c);
        update(id * 2 + 1, mid + 1, r, u, v, c);
        t[id] = t[id * 2] + t[id * 2 + 1];
    }

    void update(ll p, ll c) {
        if (p == n + 1) return;
        ll id = 1, l = 1, r = n;
        while (l < r) {
            ll mid = (l + r) / 2;
            down(id, l, r);
            if (p <= mid) {
                id = id * 2;
                r = mid;
            }
            else {
                id = id * 2 + 1;
                l = mid + 1;
            }
        }
        t[id] = c;
        while (id) {
            id >>= 1;
            t[id] = t[id * 2] + t[id * 2 + 1];
        }
    }

    ll get(ll p) {
        if (!p) return p;
        ll id = 1, l = 1, r = n;
        while (l < r) {
            ll mid = (l + r) / 2;
            down(id, l, r);
            if (p <= mid) {
                r = mid;
                id = id * 2;
            }
            else {
                l = mid + 1;
                id = id * 2 + 1;
            }
        }
        return t[id];
    }

    ll get(ll id, ll l, ll r, ll u, ll v) {
        if (r < u || l > v) return 0;
        if (u <= l && r <= v) return t[id];
        down(id, l, r);
        ll mid = (l + r) / 2;
        ll t1 = get(id * 2, l, mid, u, v);
        ll t2 = get(id * 2 + 1, mid + 1, r, u, v);
        return t1 + t2;
    }

    ll get(ll u, ll v) {
        return get(1, 1, n, u, v);
    }

    void update(ll u, ll v, ll c) {
        update(1, 1, n, u, v, c);
    }
};

ll n, q, s, t;
ll a[N];

signed main() {
    // freopen("CAU3.inp", "r", stdin);
    // freopen("CAU3.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q >> s >> t;
    fu(i, 0, n) cin >> a[i];
    SegmentTree val(n), up(n), down(n);
    fu(i, 1, n) {
        val.update(i, a[i]);
        if (a[i] > a[i - 1]) up.update(i, a[i] - a[i - 1]);
        else down.update(i, a[i - 1] - a[i]);
    }
    // cout << down.get(1, n) << el;
    // fu(i, 0, n) cout << val.get(i, i) << el;
    while (q--) {
        ll l, r, x;
        cin >> l >> r >> x;
        val.update(l, r, x);
        ll le = val.get(l - 1);
        ll cur = val.get(l);
        if (le < cur) {
            up.update(l, cur - le);
            down.update(l, 0);
        }
        else {
            down.update(l, le - cur);
            up.update(l, 0);
        }
        ll ri = val.get(r + 1);
        cur = val.get(r);
        if (ri > cur) {
            up.update(r + 1, ri - cur);
            down.update(r + 1, 0);
        }
        else {
            down.update(r + 1, cur - ri);
            up.update(r + 1, 0);
        }
        cout << -s * up.get(1, n) + t * down.get(1, n) << el;
        // fu(i, 1, n) cout << val.get(i) << ' ';
        // cout << el;
    }
    

}
accuracy: 1
time_ms: 330
memory_kb: 42412
final_rank: 18

code_snippet: #include <iostream>
using namespace std;

// コストを計算する関数
long long ct(long long high);

// グローバル変数の宣言
int N, Q, S, T;

int main() {
    // 入力の受け取り
    cin >> N >> Q >> S >> T;
    
    // 線の高さの変化を格納する配列
    long long *line = new long long[N + 1];
    
    // 初期の高さを読み込む変数
    int bh, nh;
    cin >> bh;
    
    line[0] = 0; // 初期の差分は0
    long long ans = 0; // 総コスト
    
    // 各点の高さを読み込み、差分を計算
    for (int i = 1; i <= N; ++i) {
        cin >> nh;
        line[i] = nh - bh;
        ans += ct(line[i]);
        bh = nh;
    }
    
    // クエリの処理
    int fr, to, ho;
    for (int i = 0; i < Q; ++i) {
        cin >> fr >> to >> ho;
        
        // コストの更新
        ans -= ct(line[fr]);
        line[fr] += ho;
        ans += ct(line[fr]);
        
        if (to != N) {
            ans -= ct(line[to + 1]);
            line[to + 1] -= ho;
            ans += ct(line[to + 1]);
        }
        
        // 結果を出力
        cout << ans << endl;
    }
    
    // メモリ解放
    delete[] line;
    
    return 0;
}

// コストを計算する関数
long long ct(long long high) {
    long long res;
    if (high > 0) {
        res = high * S;
    } else {
        res = high * T;
    }
    return -res;
}
accuracy: 1
time_ms: 290
memory_kb: 4696
final_rank: 11

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long int ll;

const ll BIG_NUM = 2000000000;
const ll MOD = 1000000007;
const double EPS = 0.000000001;

ll *uniformity, *partial;
int N = 1;

void init(int first_N) {
    while (N < first_N) N *= 2;
}

void add_and_updateNodes(int left, int right, ll value, int node_id, int node_left, int node_right) {
    if (right < node_left || left > node_right) return;
    else if (left <= node_left && right >= node_right) {
        uniformity[node_id] += value;
    } else {
        partial[node_id] += (min(right, node_right) - max(left, node_left) + 1) * value;
        add_and_updateNodes(left, right, value, 2 * node_id + 1, node_left, (node_left + node_right) / 2);
        add_and_updateNodes(left, right, value, 2 * node_id + 2, (node_left + node_right) / 2 + 1, node_right);
    }
}

ll getSum(int left, int right, int node_id, int node_left, int node_right) {
    if (right < node_left || left > node_right) return 0;
    else if (left <= node_left && right >= node_right) {
        return (node_right - node_left + 1) * uniformity[node_id] + partial[node_id];
    } else {
        ll sum = (min(right, node_right) - max(left, node_left) + 1) * uniformity[node_id];
        sum += getSum(left, right, 2 * node_id + 1, node_left, (node_left + node_right) / 2);
        sum += getSum(left, right, 2 * node_id + 2, (node_left + node_right) / 2 + 1, node_right);
        return sum;
    }
}

int main() {
    int first_N, Q;
    ll S, T;
    cin >> first_N >> Q >> S >> T;

    init(first_N);

    uniformity = new ll[2 * N - 1]();
    partial = new ll[2 * N - 1]();

    ll tmp, up_sum = 0, down_sum = 0, pre = 0;

    for (int i = 0; i <= first_N; ++i) {
        cin >> tmp;

        if (i > 0) {
            if (tmp > pre) {
                up_sum += (tmp - pre);
            } else {
                down_sum += (pre - tmp);
            }
            add_and_updateNodes(i - 1, i - 1, tmp, 0, 0, N - 1);
        }

        pre = tmp;
    }

    int L, R;
    ll X, pre_left_diff, pre_right_diff, next_left_diff, next_right_diff;

    for (int i = 0; i < Q; ++i) {
        cin >> L >> R >> X;
        L--;
        R--;

        if (L == 0) {
            pre_left_diff = getSum(0, 0, 0, 0, N - 1);
        } else {
            pre_left_diff = getSum(L, L, 0, 0, N - 1) - getSum(L - 1, L - 1, 0, 0, N - 1);
        }
        if (R == first_N - 1) {
            pre_right_diff = 0;
        } else {
            pre_right_diff = getSum(R + 1, R + 1, 0, 0, N - 1) - getSum(R, R, 0, 0, N - 1);
        }

        add_and_updateNodes(L, R, X, 0, 0, N - 1);

        if (L == 0) {
            next_left_diff = getSum(0, 0, 0, 0, N - 1);
        } else {
            next_left_diff = getSum(L, L, 0, 0, N - 1) - getSum(L - 1, L - 1, 0, 0, N - 1);
        }
        if (R == first_N - 1) {
            next_right_diff = 0;
        } else {
            next_right_diff = getSum(R + 1, R + 1, 0, 0, N - 1) - getSum(R, R, 0, 0, N - 1);
        }

        if (pre_left_diff <= 0) {
            down_sum -= abs(pre_left_diff);
        } else {
            up_sum -= abs(pre_left_diff);
        }

        if (pre_right_diff <= 0) {
            down_sum -= abs(pre_right_diff);
        } else {
            up_sum -= abs(pre_right_diff);
        }

        if (next_left_diff <= 0) {
            down_sum += abs(next_left_diff);
        } else {
            up_sum += abs(next_left_diff);
        }

        if (next_right_diff <= 0) {
            down_sum += abs(next_right_diff);
        } else {
            up_sum += abs(next_right_diff);
        }

        cout << T * down_sum - S * up_sum << endl;
    }

    delete[] uniformity;
    delete[] partial;

    return 0;
}
accuracy: 1
time_ms: 530
memory_kb: 11396
final_rank: 17

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q; cin >> n >> q;
    ll s,t; cin >> s >> t;
    vector<ll> a(n+1);
    for (int i = 0; i <= n; ++i) {
        cin >> a[i];
    }
    ll res = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= a[i+1]) {
            res -= s*(a[i+1] - a[i]);
        } else {
            res += t*(a[i] - a[i+1]);
        }
    }
    vector<ll> dif(n+1);
    for (int i = 1; i <= n; ++i) {
        dif[i] = a[i] - a[i-1];
    }
    while (q--) {
        int l,r; cin >> l >> r;
        ll x; cin >> x;
        if (dif[l] >= 0) {
            res += s*dif[l];
        } else {
            res += t*dif[l];
        }
        if (r != n) {
            if (dif[r+1] >= 0) {
                res += s*dif[r+1];
            } else {
                res += t*dif[r+1];
            }
        }
        dif[l] += x;
        if (dif[l] >= 0) {
            res -= s*dif[l];
        } else {
            res -= t*dif[l];
        }
        if (r != n) {
            dif[r+1] -= x;
            if (dif[r+1] >= 0) {
                res -= s*dif[r+1];
            } else {
                res -= t*dif[r+1];
            }
        }
        cout << res << "\n";
    }
}
accuracy: 1
time_ms: 60
memory_kb: 6276
final_rank: 6

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N, Q, S, T, L, R, X;
  cin >> N >> Q >> S >> T;
  vi A(N+1), D(N);
  rep(i, N+1) cin >> A[i];

  auto calc = [&](ll x) -> ll {
    return (x > 0)? (-S*x) : (-T*x);
  };

  ll temp = 0;
  rep(i, N) {
    D[i] = A[i+1] - A[i];
    temp += calc(D[i]);
  }
  rep(Q) {
    cin >> L >> R >> X;
    temp -= calc(D[L-1]);
    D[L-1] += X;
    temp += calc(D[L-1]);
    if (R < N) {
      temp -= calc(D[R]);
      D[R] -= X;
      temp += calc(D[R]);
    }
    print(temp);
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6260
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
const ll mod = 1234567;
int main() {

    ll N, Q, S, T;
    cin >> N >> Q >> S >> T;
    vll A(N + 1);
    rep(i, N + 1)cin >> A[i];
    ll an = 0;
    for (ll i = N-1; i >= 0; i--) {
        A[i + 1] -= A[i];
        if (A[i + 1] > 0)an -= S * (A[i + 1]);
        else an += T * (-A[i + 1]);
    }
    //rep(i,N+1)cout<<A[i]<<" \n"[i==N];
    //cout << an << endl;
    rep(q, Q) {
        ll L, R, X;
        cin >> L >> R >> X;
        if (A[L] > 0) {
            an += S * A[L];
        }
        else {
            an -= T * (-A[L]);
        }
        A[L] += X;
        if (A[L] > 0) {
            an -= S * A[L];
        }
        else {
            an += T * (-A[L]);
        }
        if (R!=N){
            R++;
            if (A[R] > 0) {
                an += S * A[R];
            }
            else {
                an -= T * (-A[R]);
            }
            A[R] -= X;
            if (A[R] > 0) {
                an -= S * A[R];
            }
            else {
                an += T * (-A[R]);
            }
        }
        //rep(i,N+1)cout<<A[i]<<" \n"[i==N];
        cout << an << endl;
    }
}
accuracy: 1
time_ms: 290
memory_kb: 4664
final_rank: 10

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0636.cc: Foehn Phenomena
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

/* global variables */

int as[MAX_N + 1];
ll das[MAX_N + 1];
BIT<ll> bit;

/* subroutines */

/* main */

int main() {
  int n, qn, s, t;
  scanf("%d%d%d%d", &n, &qn, &s, &t);
  for (int i = 0; i <= n; i++) scanf("%d", as + i);

  bit.init(n);
  for (int i = 1; i <= n; i++) {
    das[i] = as[i] - as[i - 1];
    if (das[i] > 0) bit.add(i, -(ll)s * das[i]);
    else if (das[i] < 0) bit.add(i, -(ll)t * das[i]);
  }

  while (qn--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    r++;

    if (das[l] > 0) bit.add(l, (ll)s * das[l]);
    else if (das[l] < 0) bit.add(l, (ll)t * das[l]);
    das[l] += x;
    if (das[l] > 0) bit.add(l, -(ll)s * das[l]);
    else if (das[l] < 0) bit.add(l, -(ll)t * das[l]);

    if (r <= n) {
      if (das[r] > 0) bit.add(l, (ll)s * das[r]);
      else if (das[r] < 0) bit.add(l, (ll)t * das[r]);
      das[r] -= x;
      if (das[r] > 0) bit.add(l, -(ll)s * das[r]);
      else if (das[r] < 0) bit.add(l, -(ll)t * das[r]);
    }

    printf("%lld\n", bit.sum(n));
  }
  return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 6548
final_rank: 8

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0636.cc: Foehn Phenomena
 */

#include<cstdio>
#include<vector>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

template <typename T>
struct BIT {
  int n;
  vector<T> bits;
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    bits.assign(n + 1, 0);
  }

  T sum(int x) {
    x = min(x, n);
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    if (x <= 0) return;
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  int lower_bound(T v) {
    int	k = 1;
    while ((k << 1) <= n) k <<=	1;
    int	x = 0;
    for	(; k > 0; k >>= 1)
      if (x + k <= n && bits[x + k] < v) {
        x += k;
        v -= bits[x];
      }
    return x + 1;
  }
};

/* global variables */

int as[MAX_N + 1], das[MAX_N + 1];
BIT<ll> bit;

/* subroutines */

/* main */

int main() {
  int n, qn, s, t;
  scanf("%d%d%d%d", &n, &qn, &s, &t);
  for (int i = 0; i <= n; i++) scanf("%d", as + i);

  bit.init(n);
  for (int i = 1; i <= n; i++) {
    das[i] = as[i] - as[i - 1];
    if (das[i] > 0) bit.add(i, -(ll)s * das[i]);
    else if (das[i] < 0) bit.add(i, -(ll)t * das[i]);
  }

  while (qn--) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    r++;

    if (das[l] > 0) bit.add(l, (ll)s * das[l]);
    else if (das[l] < 0) bit.add(l, (ll)t * das[l]);
    das[l] += x;
    if (das[l] > 0) bit.add(l, -(ll)s * das[l]);
    else if (das[l] < 0) bit.add(l, -(ll)t * das[l]);

    if (r <= n) {
      if (das[r] > 0) bit.add(l, (ll)s * das[r]);
      else if (das[r] < 0) bit.add(l, (ll)t * das[r]);
      das[r] -= x;
      if (das[r] > 0) bit.add(l, -(ll)s * das[r]);
      else if (das[r] < 0) bit.add(l, -(ll)t * das[r]);
    }

    printf("%lld\n", bit.sum(n));
  }
  return 0;
}
accuracy: 0.6363636363636364
time_ms: 70
memory_kb: 5700
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
ll imos[200000];
int main(){
	static int n,q,s,t,a[200001],l,r,x;
	cin>>n>>q>>s>>t;
	for(int i=0;i<=n;i++)
		cin>>a[i];
	ll ans=0;
	for(int i=0;i<n;i++){
		imos[i]=a[i+1]-a[i];
		if(imos[i]>0)
			ans-=(ll)imos[i]*s;
		else
			ans-=(ll)imos[i]*t;
	}
	while(cin>>l>>r>>x){
		l--;
		if(imos[l]>0)
			ans+=(ll)imos[l]*s;
		else
			ans+=(ll)imos[l]*t;
		imos[l]+=x;
		if(imos[l]>0)
			ans-=(ll)imos[l]*s;
		else
			ans-=(ll)imos[l]*t;
		if(r<n){
			if(imos[r]>0)
				ans+=(ll)imos[r]*s;
			else
				ans+=(ll)imos[r]*t;
			imos[r]-=x;
			if(imos[r]>0)
				ans-=(ll)imos[r]*s;
			else
				ans-=(ll)imos[r]*t;
		}
		cout<<ans<<endl;
	}
}
accuracy: 1
time_ms: 280
memory_kb: 5764
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define int long long
using namespace std;
int const N=233333;
int n,q,s,t,ans,a[N],d[N];
inline int calc(int x){
	return -x*(x>0?s:t);
}
signed main(){
	ios::sync_with_stdio(0);
	cin>>n>>q>>s>>t;
	for(int i=0;i<=n;i++)
		cin>>a[i],ans+=calc(d[i]=a[i]-(i?a[i-1]:0));
	while(q--){
		int l,r,x;cin>>l>>r>>x;
		cout<<(ans+=(d[l]+=x,calc(d[l])-calc(d[l]-x))+(r<n?(d[r+1]-=x,calc(d[r+1])-calc(d[r+1]+x)):0))<<"\n";
	}
}
accuracy: 1
time_ms: 190
memory_kb: 6572
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N,Q,D,U;
  cin>>N>>Q>>D>>U;
  vector<long long>A(N+1);
  for(auto &i:A)cin>>i;
  for(int i=N-1;i>=0;i--){
    A[i+1]=A[i+1]-A[i];
  }
  long long ans=0;
  for(int i=1;i<=N;i++){
    if(A[i]>0)ans-=D*A[i];
    else ans-=U*A[i];
  }
  int L,R;
  long long X;
  while(Q--){
    cin>>L>>R>>X;
    if(X<0){
      if(A[L]<0){
        ans-=U*X;
        A[L]+=X;
      }else{
        long long X2=X;
        ans+=D*min(A[L],-X2);
        X2+=min(A[L],-X2);
        ans-=U*X2;
        A[L]+=X;
      }
    }else if(X>0){
      if(A[L]>0){
        ans-=D*X;
        A[L]+=X;
      }else{
        long long X2=X;
        ans+=U*max(A[L],-X2);
        X2+=max(A[L],-X2);
        ans-=D*X2;
        A[L]+=X;
      }
    }
    if(R!=N){
      R+=1;
      X*=-1;
      if(X<0){
        if(A[R]<0){
          ans-=U*X;
          A[R]+=X;
        }else{
          long long X2=X;
          ans+=D*min(A[R],-X2);
          X2+=min(A[R],-X2);
          ans-=U*X2;
          A[R]+=X;
        }
      }else if(X>0){
        if(A[R]>0){
          ans-=D*X;
          A[R]+=X;
        }else{
          long long X2=X;
          ans+=U*max(A[R],-X2);
          X2+=max(A[R],-X2);
          ans-=D*X2;
          A[R]+=X;
        }
      }
    }
    cout<<ans<<'\n';
  }
}
accuracy: 1
time_ms: 60
memory_kb: 4660
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
//typedef int ll;
typedef pair<ll, ll> P;
const long long INF = 1e18;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
struct BIT {
    ll N;
    vector<ll> A;
    BIT(ll M) : N(M), A(M+1, 0) {}

    void add(ll i, ll x) {
        for (ll k = i; k <= N; k += (k & -k)) A[k] += x;
    }

    ll sum(ll i) {
        ll sum = 0;
        for (ll k = i; k > 0; k -= (k & -k)) sum += A[k];
        return sum;
    }

    ll sum(ll i, ll j) {
        return sum(j) - sum(i - 1);
    }

    ll lower_bound(ll x) {
        if (x <= 0) return 0;
        ll i = 0, r = 1;
        while (r < N) r = r<<1;
        for (ll j = r; j > 0; j = j >> 1) {
            if (i + j < N && A[i + j] < x) {
                x -= A[i+j];
                i+=j;
            }
        }
        return i;
    }
};
void solve() {
    ll N, Q, S, T; cin >> N >> Q >> S >> T;
    vector<ll>A(N + 1); input_arr(A, N + 1);
    BIT bt(N);
    for (ll i = 1; i <= N; i++) {
        bt.add(i, (A[i - 1] < A[i] ? -S * (A[i] - A[i - 1]) : T * (A[i - 1] - A[i])));
    }
    BIT bt2(N + 1);
    for (ll i = 0; i < Q; i++) {
        ll l, r, x; cin >> l >> r >> x;
        bt2.add(l, x);
        bt.add(l, -bt.sum(l, l));
            ll num1 = A[l] + bt2.sum(l);
            ll num2 = A[l - 1] + bt2.sum(l - 1);
            bt.add(l, (num2 < num1 ? -S * (num1 - num2) : T * (num2 - num1)));
        r++;
        if (r <= N) {
            bt2.add(r , -x);
            bt.add(r, -bt.sum(r, r));
                ll num1 = A[r] + bt2.sum(r);
                ll num2 = A[r - 1] + bt2.sum(r - 1);
                bt.add(r, (num2 < num1 ? -S * (num1 - num2) : T * (num2 - num1)));
        }
        cout << bt.sum(N) << endl;
    }
}
int main() {
    solve();
}
accuracy: 1
time_ms: 330
memory_kb: 7868
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
using namespace std;
using ll = long long;
template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){return (a+b-1)/b;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    LL(n,q,s,t);
    vector<ll> a(n+1),d(n);
    in(a);
    ll ans=0;
    rep(i,n){
        d[i]=a[i+1]-a[i];
        ans+=(d[i]>0?-s:-t)*d[i];
    }
    int l,r,x;
    while(q--){
        in(l,r,x);
        l--;
        ans-=(d[l]>0?-s:-t)*d[l];
        d[l]+=x;
        ans+=(d[l]>0?-s:-t)*d[l];
        if(r<n){
            ans-=(d[r]>0?-s:-t)*d[r];
            d[r]-=x;
            ans+=(d[r]>0?-s:-t)*d[r];
        }
        out(ans);
    }
}
accuracy: 1
time_ms: 60
memory_kb: 6308
final_rank: 7

code_snippet: #include<iostream>

using namespace std;

#define Long long long

Long DeltaT(Long deltaA, Long S, Long T)
{
	return abs(deltaA) * (deltaA < 0 ? -S : T);
}

int main()
{
	Long N, Q, S, T;
	cin >> N >> Q >> S >> T;
	Long* DeltaA = new Long[N];
	Long A;
	cin >> A;
	Long wind = 0;
	for (int i = 0; i < N; i++)
	{
		DeltaA[i] = A;
		cin >> A;
		DeltaA[i] = DeltaA[i] - A;
		wind += DeltaT(DeltaA[i],S,T);
	}
	Long L, R, X;
	for (int i = 0; i < Q; i++)
	{
		cin >> L >> R >> X;
		DeltaA[L - 1] -= X;
		wind += (DeltaT(DeltaA[L - 1], S, T) - DeltaT(DeltaA[L - 1] + X, S, T));
		if (R < N)
		{
			DeltaA[R] += X;
			wind += (DeltaT(DeltaA[R], S, T) - DeltaT(DeltaA[R] - X, S, T));
		}
		cout << wind << endl;
	}

	//system("pause");
}
accuracy: 1
time_ms: 290
memory_kb: 4972
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define rep(i, n) for(int i = 0; i < int(n); i++)

int main(){
    int n, q;
    lint s, t;
    cin >> n >> q >> s >> t;
    vector<lint> a(n + 1);
    rep(i, n + 1) cin >> a[i];
    vector<lint> diff(n);
    rep(i, n) diff[i] = a[i + 1] - a[i];
    
    auto degree = [&](lint x){ if(x > 0) return x * -s; else return x * -t; };
    
    lint ans = 0;
    rep(i, n) ans += degree(diff[i]);
    
    rep(_, q){
        int l, r;
        lint x;
        cin >> l >> r >> x;
        l--;
        
        ans -= degree(diff[l]);
        diff[l] += x;
        ans += degree(diff[l]);
        
        if(r < n){
            ans -= degree(diff[r]);
            diff[r] -= x;
            ans += degree(diff[r]);
        }
        
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 290
memory_kb: 6264
final_rank: 14

code_snippet: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, q, s, t; cin >> n >> q >> s >> t;
  vector<int> a(n + 1); REP(i, n + 1) cin >> a[i];
  vector<ll> b(n);
  REP(i, n) b[i] = a[i + 1] - a[i];
  auto foehn = [&](int i) -> ll {
    return b[i] > 0 ? -s * b[i] : t * -b[i];
  };
  ll ans = 0;
  REP(i, n) ans += foehn(i);
  while (q--) {
    int l, r, x; cin >> l >> r >> x;
    ans -= foehn(l - 1);
    b[l - 1] += x;
    ans += foehn(l - 1);
    if (r < n) {
      ans -= foehn(r);
      b[r] -= x;
      ans += foehn(r);
    }
    cout << ans << '\n';
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5460
final_rank: 2

code_snippet: #include<cstdio>
#include<algorithm>
using namespace std;
int a[200005];
long long sa[200005];
int main(void)
{
	int n,q,s,t,x,l,r,i,j;
	long long sum,psum,msum;
	scanf("%d %d %d %d",&n,&q,&s,&t);
	for(i=0;i<=n;i++){
		scanf("%d",&a[i]);
	}
	psum=0;
	msum=0;
	sa[0]=0;
	for(i=1;i<=n;i++){
		sa[i]=a[i]-a[i-1];
		if(sa[i]<0){
			msum+=sa[i];
		}
		else{
			psum+=sa[i];
		}
	}
	for(i=0;i<q;i++){
		scanf("%d %d %d",&l,&r,&x);
		if(sa[l]>=0){
			if(x+sa[l]>=0){
				psum+=x;
				sa[l]+=x;
			}
			else{
				psum-=sa[l];
				msum+=sa[l]+x;
				sa[l]+=x;
			}
		}
		else{
			if(x+sa[l]>=0){
				msum-=sa[l];
				psum+=sa[l]+x;
				sa[l]+=x;
			}
			else{
				msum+=x;
				sa[l]+=x;
			}
		}
		x=-x;
		if(r+1<=n){
			if(sa[r+1]>=0){
				if(x+sa[r+1]>=0){
					psum+=x;
					sa[r+1]+=x;
				}
				else{
					psum-=sa[r+1];
					msum+=sa[r+1]+x;
					sa[r+1]+=x;
				}
			}
			else{
				if(x+sa[r+1]>=0){
					msum-=sa[r+1];
					psum+=sa[r+1]+x;
					sa[r+1]+=x;
				}
				else{
					msum+=x;
					sa[r+1]+=x;
				}
			}
		}
		sum=-psum*s-msum*t;
		printf("%lld\n",sum);
	}
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 5048
final_rank: 3