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;
typedef long long int ll;
const int maxn = 2e5+10;
ll n, q, a[maxn];
ll sum, dif[maxn], s, t;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q >> s >> t;
for(int i = 0 ; i <= n ; i++) cin >> a[i];
for(int i = 1 ; i <= n ; i++)
{
dif[i] = a[i]-a[i-1];
if(dif[i] <= 0) sum += abs(dif[i]*t);
else sum -= abs(dif[i]*s);
}
//cout << sum << endl;
dif[0] = dif[n+1] = 0;
//for(int i = 1 ; i <= n ; i++) cout << dif[i] << ' ';
//cout << endl;
for(int i = 0 ; i < q ; i++)
{
int l, r, x;
cin >> l >> r >> x;
//cout << dif[l] << ' ' << dif[r+1] << endl;
if(dif[l] <= 0) sum -= abs(dif[l]*t);
else sum += abs(dif[l]*s);
if(dif[r+1] <= 0) sum -= abs(dif[r+1]*t);
else sum += abs(dif[r+1]*s);
dif[l] += x;
if(r+1 <= n) dif[r+1] -= x;
if(dif[l] <= 0) sum += abs(dif[l]*t);
else sum -= abs(dif[l]*s);
if(dif[r+1] <= 0) sum += abs(dif[r+1]*t);
else sum -= abs(dif[r+1]*s);
//cout << dif[l] << ' ' << dif[r+1] << endl;
cout << sum << "\n";
// for(int i = 1 ; i <= n ; i++) cout << dif[i] << ' ';
// cout << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |