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 <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int64_t n,q,s,t,akt,pop,szt=0;
cin >> n >> q >> s >> t;
vector<int64_t> zmtp;
cin >> pop;
for (int i=0; i<n; i++){
if (i>0) pop=akt;
cin >> akt;
if (akt>pop) zmtp.push_back((pop-akt)*s);
else zmtp.push_back((pop-akt)*t);
szt+=zmtp[i];
}
//for (int i=0; i<n; i++) cout << zmtp[i] << ' ';
//cout << '\n';
for (int i=0; i<q; i++){
int64_t l,r,x;
cin >> l >> r >> x;
l--;
r--;
int64_t aktl=zmtp[l];
if (zmtp[l]>0 and zmtp[l]>=x*t) zmtp[l]-=x*t;
else if (zmtp[l]>0){
x-=zmtp[l]/t;
zmtp[l]=-x*s;
}
else if (zmtp[l]-x*s<=0) zmtp[l]-=x*s;
else{
x+=zmtp[l]/s;
zmtp[l]=x*t;
//cout << 'a';
}
if (r+1<n){
int64_t aktr=zmtp[r+1];
if (aktr<0 and aktr+x*s<=0) zmtp[r+1]+=x*s;
else if (aktr<0){
x+=aktr/s;
zmtp[r+1]=x*t;
}
else if (aktr+x*t>=0) zmtp[r+1]+=x*t;
else{
x-=zmtp[r+1]/t;
zmtp[r+1]=x*s;
}
szt+=zmtp[r+1]-aktr;
//cout << zmtp[r+1] << ' ' << aktr << ' ' << zmtp[r+1]-aktr << ' ';
}
szt+=zmtp[l]-aktl;
//cout << zmtp[l] << ' ' << aktl << ' ' << zmtp[l]-aktl << '\n';
//for (int i=0; i<n; i++) cout << zmtp[i] << ' ';
//cout << '\n';
cout << szt << '\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... |