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;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n,ans = 0,q,s,t,l,r,k;
cin >> n >> q >> s >> t;
vector<long long> haha(n+1);
vector<long long> br(n);
for(long long i = 0; i <= n; i++) {
cin >> haha[i];
}
for(long long i = 0; i < n; i++) {
br[i] = haha[i]-haha[i+1];
if(br[i] > 0) {
ans+=t*br[i];
}
else {
ans+=s*br[i];
}
}
for(long long i = 0; i < q; i++) {
cin >> l >> r >> k;
l--;
if(br[l] > 0) {
ans-=t*br[l];
}
else {
ans-=s*br[l];
}
br[l]-=k;
if(br[l] > 0) {
ans+=t*br[l];
}
else {
ans+=s*br[l];
}
if(r < n) {
if(br[r] > 0) {
ans-=t*br[r];
}
else {
ans-=s*br[r];
}
br[r]+=k;
if(br[r] > 0) {
ans+=t*br[r];
}
else {
ans+=s*br[r];
}
}
cout << ans << "\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... |