제출 #899520

#제출 시각아이디문제언어결과실행 시간메모리
899520oblantisFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
220 ms19428 KiB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18;
const int mod = 1e9+7;
const int maxn = 2e5 + 2;
int n, s, t, q;
ll a[maxn], b[maxn], xl, xr, x, it;
ll y, l, ans;
ll tr[maxn * 4];
void build(int v, int l, int r){
	if(l == r){
		tr[v] = a[l];
		return;
	}
	build(v * 2 + 1, l, (l + r) / 2), build(v * 2 + 2, (l + r) / 2 + 1, r);
}
void upd(int v, int l, int r){
	if(xl <= l && r <= xr){
		tr[v] += x;
		return;
	}
	if(r < xl || xr < l)return;
	upd(v * 2 + 1, l, (l + r) / 2), upd(v * 2 + 2, (l + r) / 2 + 1, r);
}
void get(int v, int l, int r){
	y += tr[v];
	if(l == r)return;
	if((l + r) / 2 >= it){
		get(v * 2 + 1, l, (l + r) / 2);
	}
	else get(v * 2 + 2, (l + r) / 2 + 1, r);
}
void fun(ll x, bool wt){
	if(x > 0)x = -x * s;
	else x = -x * t;
	if(wt)ans += x;
	else ans -= x;
}
void solve() {
	cin >> n >> q >> s >> t;
	for(int i = 0; i <= n; i++){
		cin >> a[i];
		if(i){
			b[i] = a[i] - a[i - 1];
			fun(b[i], 1);
		}
	}
	build(0, 0, n);
	while(q--){
		cin >> xl >> xr >> x;
		upd(0, 0, n);
		y = 0, it = xl;
		get(0, 0, n);
		l = y, it = it - 1, y = 0;
		get(0, 0, n);
		fun(b[xl], 0);
		b[xl] = l - y;
		fun(b[xl], 1);
		if(xr < n){
			it = xr + 1, y = 0;
			get(0, 0, n);
			l = y, it = it - 1, y = 0;
			get(0, 0, n);
			fun(b[xr + 1], 0);
			b[xr + 1] = l - y;
			fun(b[xr + 1], 1);
		}
		cout << ans << '\n';
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...