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 <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=2e5+5;
const int mod=998244353;
const int mxlogN=40;
const int mxK=26;
const int inf=2e9;
const int K=600;
ll a[mxN], ft[mxN];
void add(int i, int v)
{
while(i<mxN)
{
ft[i]+=v;
i+=i&-i;
}
}
ll sum(int i)
{
if(!i) return 0;
ll s=0;
while(i)
{
s+=ft[i];
i-=i&-i;
}
return s;
}
ll check(int i, ll s, ll t)
{
if(a[i+1]-a[i]>0) return -(a[i+1]-a[i])*s;
return -(a[i+1]-a[i])*t;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q; ll s,t; cin >> n >> q >> s >> t;
for(int i=1; i<=n+1; i++)
{
cin >> a[i];
add(i,a[i]-a[i-1]);
}
ll ans=0;
for(int i=n; i; i--) ans+=check(i,s,t);
while(q--)
{
int l, r, x; cin >> l >> r >> x; l++, r++;
a[l]=sum(l), a[l-1]=sum(l-1), a[r]=sum(r), a[r+1]=sum(r+1);
ans-=check(l-1,s,t);
if(r<=n) ans-=check(r,s,t);
add(l , x);
add(r+1,-x);
a[l]=sum(l), a[l-1]=sum(l-1), a[r]=sum(r), a[r+1]=sum(r+1);
ans+=check(l-1,s,t);
if(r<=n) ans+=check(r,s,t);
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |