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;
using ll=long long;
const int MAX=2*1e5+7;
/*
const int base=1<<20;
ll drzewo[2*base];
void ppush(int a, int b, ll w){
a += base-1;
b += base+1;
while (a/2!=b/2){
if (a%2==0) drzewo[a+1]+=w;
if (b%2==1) drzewo[b-1]+=w;
a/=2;
b/=2;
}
}
void get(int a){
int a2=a;
a+=base;
ll wyn=0;
while (a>0){
wyn += drzewo[a];
a /= 2;
}
drzewo[base+a2] = wyn;
}
*/
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, q, l, r;
ll s, t, x, wyn=0, poprzednia;
cin >> n >> q >> s >> t;
ll roznice[MAX];
cin >> poprzednia;
for (int i=1; i<=n; i++){
cin >> x;
roznice[i] = x-poprzednia;
if (poprzednia < x) wyn -= s*roznice[i];
else wyn -= t*roznice[i];
poprzednia = x;
}
for (int i=0; i<q; i++){
cin >> l >> r >> x;
//cout << wyn << endl;
//cout << roznice[l] << " " << roznice[r+1] << endl;
if (roznice[l] > 0) wyn += s*(roznice[l]);
else wyn += t*(roznice[l]);
if (r!=n){
if (roznice[r+1] > 0) wyn += s*(roznice[r+1]);
else wyn += t*(roznice[r+1]);
}
roznice[l] += x;
if (r<n) roznice[r+1] -= x;
if (roznice[l] > 0) wyn -= s*(roznice[l]);
else wyn -= t*(roznice[l]);
if (r!=n){
if (roznice[r+1] > 0) wyn -= s*(roznice[r+1]);
else wyn -= t*(roznice[r+1]);
}
cout << wyn << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |