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 int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, Q, S, T;
cin >> N;
cin >> Q;
cin >> S;
cin >> T;
ll Temp = 0;
vll Ad(N+2);
ll last = 0;
rep(n,0,N+1) {
ll a;
cin >> a;
Ad[n] = a-last;
last = a;
}
rep(n,1,N+1) {
ll diff = Ad[n];
Temp += diff > 0 ? -diff*S : -diff*T;
}
rep(q,0,Q) {
ll L, R, X;
cin >> L;
cin >> R;
cin >> X;
ll one = Ad[L]*(Ad[L] > 0 ? S : T);
ll two = Ad[R+1]*(Ad[R+1] > 0 ? S : T);
Ad[L] += X;
Ad[R+1] -= X;
Temp += one + Ad[L]*(Ad[L] > 0 ? -S : -T);
if(R+1 <= N)
Temp += two + Ad[R+1]*(Ad[R+1] > 0 ? -S : -T);
cout << Temp << '\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... |