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 <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
n++;
vector<int> a(n);
for (auto &x : a) {
cin >> x;
}
vector<int> dl(n - 1);
for (int i = 0; i + 1 < n; i++) {
dl[i] = a[i + 1] - a[i];
}
auto sl = [&](int i) {
if (i < 0) return (int)0;
if (i + 1 == n) return (int)0;
if (dl[i] >= 0) return dl[i] * s;
else return dl[i] * t;
};
int ans = 0;
for (int i = 0; i + 1 < n; i++) {
ans += sl(i);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans -= sl(l - 1);
ans -= sl(r);
dl[l - 1] += x;
if (r + 1 < n) dl[r] -= x;
ans += sl(l - 1);
ans += sl(r);
cout << -ans << '\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... |