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;
typedef long long ll;
const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define mp make_pair
#define pb push_back
bool mini(auto &x, const auto &y) {
if (y < x) {
x = y;
return 1;
}
return 0;
}
bool maxi(auto &x, const auto &y) {
if (y > x) {
x = y;
return 1;
}
return 0;
}
void run();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
const int N = (int) 2e5 + 123;
int n, q;
ll s, t;
ll a[N], b[N];
ll f(ll x) {
if (x > 0) {
return -x * s;
} else {
return -x * t;
}
}
void run() {
cin >> n >> q >> s >> t;
rep(i, 0, n + 1) {
cin >> a[i];
}
rep(i, 0, n) {
b[i] = a[i + 1] - a[i];
}
ll ans = 0;
rep(i, 0, n) {
ans += f(b[i]);
}
while (q--) {
int l, r;
ll x;
cin >> l >> r >> x;
ans -= f(b[l - 1]);
b[l - 1] += x;
ans += f(b[l - 1]);
if (r < n) {
ans -= f(b[r]);
b[r] -= x;
ans += f(b[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... |