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>
using namespace std;
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 220000
ll n, q, s, t, bit[maxn];
void att(ll pos, ll val) {
for(ll i = pos; i <= n && i > 0; i+= i&-i)
bit[i]+= val;
}
ll qrr(ll pos) {
ll sum = 0;
for(ll i = pos; i > 0; i-= i&-i)
sum+= bit[i];
return sum;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
//freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
cin >> n >> q >> s >> t;
for(ll i = 0; i <= n; i++) {
ll a; cin >> a;
att(i,a);
att(i+1,-a);
}
ll up = 0;
ll dw = 0;
for(ll i = 1; i <= n; i++) {
ll l1 = qrr(i-1);
ll l2 = qrr(i);
if(l1 < l2) {
up+= abs(l1-l2);
}
else {
dw+= abs(l1-l2);
}
}
while(q--) {
ll l, r, x;
cin >> l >> r >> x;
ll l1 = qrr(l-1);
ll l2 = qrr(l);
if(l1 < l2) {
up-= abs(l1-l2);
}
else {
dw-= abs(l1-l2);
}
ll r1 = qrr(r);
ll r2 = qrr(r+1);
if(r1 < r2 && r != n) {
up-= abs(r1-r2);
}
else if(r != n) {
dw-= abs(r1-r2);
}
att(l,x);
att(r+1,-x);
l1 = qrr(l-1);
l2 = qrr(l);
if(l1 < l2) {
up+= abs(l1-l2);
}
else {
dw+= abs(l1-l2);
}
r1 = qrr(r);
r2 = qrr(r+1);
if(r1 < r2 && r != n) {
up+= abs(r1-r2);
}
else if(r != n) {
dw+= abs(r1-r2);
}
cout << dw*t - up*s << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |