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 <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
#include <iterator>
#include <stack>
#include <map>
#include <math.h>
#include <bitset>
#include <deque>
#include <string>
#include <tuple>
#include <queue>
#include <numeric>
#include <complex>
#include <assert.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define ld long long double
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define mod 1000000007ll
#define INF 1e18
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin (), (x).end ()
#define sz(x) (ll) (x).size ()
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define rank rnk
#define log lg
#define fast \
ios_base::sync_with_stdio (false); \
cin.tie (NULL); \
cout.tie (NULL)
using namespace std;
struct FenwickTree {
vector<ll> bit; // binary indexed tree
ll n;
FenwickTree(ll n) {
this->n = n;
bit.assign(n, 0);
}
FenwickTree(vector<ll> a) : FenwickTree(a.size()) {
for (size_t i = 0; i < a.size(); i++)
add(i, a[i]);
}
ll sum(ll r) {
ll ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
ll sum(ll l, ll r) {
return sum(r) - sum(l - 1);
}
void add(ll idx, ll delta) {
for (; idx < n; idx = idx | (idx + 1))
bit[idx] += delta;
}
};
signed main()
{
fast;
ll n,q,s,t;
cin>>n>>q>>s>>t;
vector <ll> a(n+1);
rep(i,0,n)
cin>>a[i];
ll c=0;
rep(i,1,n)
c+=(a[i]>a[i-1]?s*(a[i-1]-a[i]):t*(a[i-1]-a[i]));
FenwickTree f(n+2);
while(q--)
{
ll l,r,del;
cin>>l>>r>>del;
ll cl=a[l]+f.sum(l);
ll clprev=a[l-1]+f.sum(l-1);
ll nl=cl+del;
c+=(nl>clprev?s*(clprev-nl):t*(clprev-nl))-(cl>clprev?s*(clprev-cl):t*(clprev-cl));
if(r!=n)
{
ll cr=a[r]+f.sum(r);
ll crnext=a[r+1]+f.sum(r+1);
ll nr=cr+del;
c+=(crnext>nr?s*(nr-crnext):t*(nr-crnext))-(crnext>cr?s*(cr-crnext):t*(cr-crnext));
}
f.add(l,del);
f.add(r+1,-del);
cout<<c<<endl;
}
return 0;
}
/*
3 5 1 2
0
4
1
8
1 2 2
1 1 -2
2 3 5
1 2 -1
1 3 5
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |