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>
#define DIM 200010
using namespace std;
long long aib[DIM],v[DIM];
int n,q,x,y,i;
long long s,t,val;
void update (int p, long long val){
for (;p<=n;p+=(p&-p))
aib[p] += val;
}
long long query (int p){
if (p <= 0)
return 0;
long long sol = 0;
for (;p;p-=(p&-p))
sol += aib[p];
return sol;
}
int main (){
//ifstream cin ("date.in");
//ofstream cout ("date.out");
cin>>n>>q>>s>>t;
long long sum = 0;
for (i=0;i<=n;i++){
cin>>v[i];
if (!i)
continue;
if (v[i-1] < v[i])
sum -= s * (v[i] - v[i-1]);
else sum += t * (v[i-1] - v[i]);
update (i,v[i]);
update (i+1,-v[i]);
}
for (;q--;){
cin>>x>>y>>val;
long long nr = query (x-1), nr2 = query (x);
if (nr < nr2)
sum += s * (nr2 - nr);
else sum -= t * (nr - nr2);
nr = query (y), nr2 = query (y+1);
if (y < n){
if (nr < nr2)
sum += s * (nr2 - nr);
else sum -= t * (nr - nr2);
}
update (x,val);
update (y+1,-val);
nr = query (x-1), nr2 = query (x);
if (nr < nr2)
sum -= s * (nr2 - nr);
else sum += t * (nr - nr2);
nr = query (y), nr2 = query (y+1);
if (y < n){
if (nr < nr2)
sum -= s * (nr2 - nr);
else sum += t * (nr - nr2);
}
cout<<sum<<"\n";
}
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... |