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;
#define int long long
const int N = 200005;
int n , q , s , t , ans;
int a[N] , bit[N];
signed main(){
//freopen("1.inp","r",stdin);
cin >> n >> q >> s >> t;
n++;
for(int i = 1 ; i <= n ; ++ i)
cin >> a[i];
for(int i = 2; i <= n ; i ++){
bit[i] = a[i] - a[i - 1];
if (bit[i] >= 0) ans -= bit[i] * s;
else ans -= bit[i] * t;
}
while(q--){
int l , r , val;
cin >> l >> r >> val;
l++ ; r++;
if (bit[l] >= 0) ans += bit[l] * s;
else ans += bit[l] * t;
bit[l] += val;
if (bit[l] >= 0) ans -= bit[l] * s;
else ans -= bit[l] * t;
if (r != n) {
if (bit[r + 1] >= 0) ans += bit[r + 1] * s;
else ans += bit[r + 1] * t;
bit[r + 1] -= val;
if (bit[r + 1] >= 0) ans -= bit[r + 1] * s;
else ans -= bit[r + 1] * t;
}
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... |