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;
void upd(vector<long long>& tree, long long w, long long in, long long v) {
in += w;
tree[in] += v;
for (in /= 2; in > 0; in /= 2) {
tree[in] = tree[2 * in] + tree[2 * in + 1];
}
}
long long sum(const vector<long long>& tree, long long w, long long left, long long right) {
long long result = 0;
left += w;
right += w;
while (left < right) {
if (left % 2 == 1) result += tree[left++];
if (right % 2 == 1) result += tree[--right];
left /= 2;
right /= 2;
}
return result;
}
long long li(vector <long long> domy, vector<long long> v, long long i) {
return sum(domy, v.size(), 0, i + 1) + v[i];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, q, s, t, w = 0, l, p, va, p1, p2, l1, l2;
cin >> n >> q >> s >> t;
n += 1;
vector<long long> domy(2 * n);
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
cin >> v[i];
if (i > 0 && v[i - 1] < v[i]) {
w -= s * (v[i] - v[i - 1]);
}
else if(i > 0 && v[i - 1] > v[i]) {
w += t * (v[i - 1] - v[i]);
}
}
for (long long i = 0; i < q; i++) {
cin >> l >> p >> va;
l1 = li(domy, v, l - 1);
l2 = li(domy, v, l);
if (l1 < l2) {
w += s * (l2 - l1);
}
else {
w -= t * (l1 - l2);
}
if (p < n - 1) {
p1 = li(domy, v, p);
p2 = li(domy, v, p + 1);
if (p1 < p2) {
w += s * (p2 - p1);
}
else {
w -= t * (p1 - p2);
}
}
upd(domy, n, l, va);
if (p < n - 1) {
upd(domy, n, p + 1, -va);
}
l1 = li(domy, v, l - 1);
l2 = li(domy, v, l);
if (l1 < l2) {
w -= s * (l2 - l1);
}
else {
w += t * (l1 - l2);
}
if (p < n - 1) {
p1 = li(domy, v, p);
p2 = li(domy, v, p + 1);
if (p1 < p2) {
w -= s * (p2 - p1);
}
else {
w += t * (p1 - p2);
}
}
cout << w << 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... |