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>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(ll i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
#define ull unsigned long long
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 2e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 15 * 10, pr = 31;
const int base = (1 << 18);
const ll inf = 2e9, neg = -69420, add = 1e9;
ll n, q, s, t;
ll a[mxn + 1], dif[mxn + 1];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
ll ans = 0;
for(int i = 0; i <= n; i++){
cin >> a[i];
if(i){
dif[i] = a[i] - a[i - 1]; ans += ((dif[i] > 0) ? -s * dif[i] : t * -dif[i]);
}
}
for(int i = 0; i < q; i++){
ll l, r, x; cin >> l >> r >> x;
ans -= ((dif[l] > 0) ? -s * dif[l] : t * -dif[l]);; dif[l] += x;
ans += ((dif[l] > 0) ? -s * dif[l] : t * -dif[l]);;
if(r != n){
ans -= ((dif[r + 1] > 0) ? -s * dif[r + 1] : t * -dif[r + 1]);; dif[r + 1] -= x;
ans += ((dif[r + 1] > 0) ? -s * dif[r + 1] : t * -dif[r + 1]);;
}
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... |