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>
//#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |