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 endl '\n'
using namespace std;
const long long MAXN = 2e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, q, s, t;
long long a[MAXN];
void read_array()
{
cin >> n >> q >> s >> t;
for (long long i = 0; i <= n; ++ i)
cin >> a[i];
}
long long p[MAXN];
long long ans = 0;
void precompute()
{
for (long long i = 1; i <= n; ++ i)
{
p[i] = a[i] - a[i-1];
if(p[i] > 0)ans -= s * abs(p[i]);
else ans += t * abs(p[i]);
}
}
void solve()
{
long long left, right, x;
while(q --)
{
cin >> left >> right >> x;
if(p[left] > 0)ans += s * abs(p[left]);
else ans -= t * abs(p[left]);
p[left] += x;
if(p[left] > 0)ans -= s * abs(p[left]);
else ans += t * abs(p[left]);
if(right != n)
{
if(p[right+1] > 0)ans += s * abs(p[right+1]);
else ans -= t * abs(p[right+1]);
p[right+1] -= x;
if(p[right+1] > 0)ans -= s * abs(p[right + 1]);
else ans += t * abs(p[right + 1]);
}
cout << ans << endl;
}
}
int main()
{
speed();
read_array();
precompute();
solve();
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... |