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;
using ll = long long;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
int pop, ter;
cin >> pop;
vector<int> roz;
for(int i = 0; i < n; ++i)
{
cin >> ter;
roz.push_back(ter - pop);
pop = ter;
}
roz.push_back(0);
ll odp = 0;
for(int i = 0; i < n; ++i)
{
if(roz[i] > 0)
odp -= s*roz[i];
else
odp -= t*roz[i];
}
for(int i = 0; i < q; ++i)
{
int l, r, x;
cin >> l >> r >> x;
int a = roz[l-1];
int b = roz[r];
roz[l-1] += x;
roz[r] -= x;
if(a > 0 && roz[l-1] <= 0)
odp += s*a - t*roz[l-1];
if(a <= 0 && roz[l-1] > 0)
odp -= s*roz[l-1] - t*a;
if(a > 0 && roz[l-1] > 0)
odp += s*a - s*roz[l-1];
if(a <= 0 && roz[l-1] <= 0)
odp += t*a - t*roz[l-1];
if(r >= n)
{
cout << odp << "\n";
continue;
}
if(b > 0 && roz[r] <= 0)
odp += s*b - t*roz[r];
if(b <= 0 && roz[r] > 0)
odp -= s*roz[r] - t*b;
if(b > 0 && roz[r] > 0)
odp += s*b - s*roz[r];
if(b <= 0 && roz[r] <= 0)
odp += t*b - t*roz[r];
cout << odp << "\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... |