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;
ifstream fin ("echilibru.in");
ofstream fout ("echilibru.out");
typedef long long ll;
int n, q;
ll aib[200002], a[200002], s, t;
ll query (int x) {
ll s = 0;
for (int i = x; i; i -= (i & -i))
s += aib[i];
return s;
}
void update (int x, ll val) {
if (x > n)
return;
for (int i = x; i <= n; i += (i & -i))
aib[i] += val;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
n++;
for (int i = 1; i <= n; i++) {
cin >> a[i];
update(i, a[i]);
update(i + 1, -a[i]);
}
ll sum = 0;
for (int i = 1; i < n; i++) {
if (a[i] < a[i + 1])
sum += (a[i] - a[i + 1]) * s;
else
sum += (a[i] - a[i + 1]) * t;
}
ll l, r, x;
while (q--) {
cin >> l >> r >> x;
l++;r++;
if (l > 1) {
ll val1 = query(l), val2 = query(l - 1);
if (val2 < val1)
sum -= (val2 - val1) * s;
else
sum -= (val2 - val1) * t;
}
if (r < n) {
ll val1 = query(r + 1), val2 = query(r);
if (val2 < val1)
sum -= (val2 - val1) * s;
else
sum -= (val2 - val1) * t;
}
update(l, x);
update(r + 1, -x);
if (l > 1) {
ll val1 = query(l), val2 = query(l - 1);
if (val2 < val1)
sum += (val2 - val1) * s;
else
sum += (val2 - val1) * t;
}
if (r < n) {
ll val1 = query(r + 1), val2 = query(r);
if (val2 < val1)
sum += (val2 - val1) * s;
else
sum += (val2 - val1) * t;
}
cout << sum << "\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... |