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;
#define pb push_back
#define all(s) s.begin(), s.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
ll n, q, s, t;
ll getTempDiff(ll heightLeft, ll heightRight)
{
ll heightDif = abs(heightLeft - heightRight), res = 0;
if (heightLeft < heightRight)
res -= s * heightDif;
else
res += t * heightDif;
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q >> s >> t;
vector<ll> height(n + 1, 0);
for (int i = 0; i <= n; i++)
cin >> height[i];
ll temp = 0;
for (int i = 0; i < n; i++)
temp += getTempDiff(height[i], height[i + 1]);
while (q--)
{
ll l, r, k;
cin >> l >> r >> k;
if (s == t)
{
temp -= getTempDiff(height[l - 1], height[l]);
if (r < n)
temp -= getTempDiff(height[r], height[r + 1]);
height[l] += k;
if (r != l)
height[r] += k;
temp += getTempDiff(height[l - 1], height[l]);
if (r < n)
temp += getTempDiff(height[r], height[r + 1]);
}
else
{
for (int i = l + 1; i <= r - 1; i++)
height[i] += k;
}
cout << temp << '\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... |