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 <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int N, Q, S, T;
long long point(int a)
{
long long cur;
if (a > 0) cur = -S * a;
else cur = -T * a;
return cur;
}
int main()
{
cin >> N >> Q >> S >> T;
vector<int> spots(N+1, 0), diff(N+2, 0);
for (int i = 0; i <= N; ++i) cin >> spots[i];
for (int i = 0; i < N; ++i) diff[i] = spots[i+1] - spots[i];
long long cur = 0;
for (int i = 0; i < N; ++i) {
cur += point(diff[i]);
}
// cout << cur << endl;
for (int q = 0; q < Q; ++q) {
int l, r, x;
cin >> l >> r >> x;
if (l > 0) {
cur -= point(diff[l-1]);
diff[l-1] += x;
cur += point(diff[l-1]);
}
if (r < N) {
cur -= point(diff[r]);
diff[r] -= x;
cur += point(diff[r]);
}
cout << cur << endl;
}
// for (int i = 0; i < N; ++i) cout << diff[i] << 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... |