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>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 200010
int N, Q;
lld S, T;
lld A[MAXN], bit[MAXN];
void update(int idx, lld val) {
while(idx < MAXN) {
bit[idx] += val;
idx += idx&-idx;
}
}
lld q(int idx) {
lld rez = A[idx];
while(idx) {
rez += bit[idx];
idx -= idx&-idx;
}
return rez;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0);
cin >> N >> Q >> S >> T;
lld score = 0;
cin >> A[0];
for(int i = 1; i <= N; i++) {
cin >> A[i];
if(A[i-1] < A[i]) score -= S*(A[i]-A[i-1]);
else score -= T*(A[i]-A[i-1]);
}
while(Q--) {
int L, R; lld val; cin >> L >> R >> val;
if(q(L-1) < q(L)) score -= S*(q(L-1)-q(L));
else score -= T*(q(L-1)-q(L));
if(R != N) {
if(q(R) < q(R+1)) score -= S*(q(R)-q(R+1));
else score -= T*(q(R)-q(R+1));
}
update(L, +val);
update(R+1, -val);
if(q(L-1) < q(L)) score -= S*(q(L)-q(L-1));
else score -= T*(q(L)-q(L-1));
if(R != N) {
if(q(R) < q(R+1)) score += S*(q(R)-q(R+1));
else score += T*(q(R)-q(R+1));
}
cout << score << 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... |