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 ll
#define MAX LLONG_MAX
#define st first
#define nd second
#define endl '\n'
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef pair< int, int > ii;
typedef pair< int, ii > iii;
typedef vector< int > vi;
typedef vector< ii > vii;
typedef vector< iii > viii;
typedef vector< vi > vvi;
typedef vector< vii > vvii;
typedef vector< viii > vviii;
const int N = 2e5 + 5;
int n, q, s, t;
int a[N], suf[N];
int sum = 0;
int cal(int v){
if(v > 0) return - v * s;
else return - v * t;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q >> s >> t;
for(int i=0; i<=n; i++) cin >> a[i];
for(int i=1; i<=n; i++){
suf[i] = a[i] - a[i-1];
sum += cal(suf[i]);
}
while(q--){
int l, r, v; cin >> l >> r >> v;
// sum -= cal(suf[l]) + cal(suf[r+1]);
// suf[l] += v; suf[r+1] -= v;
// sum += cal(suf[l]) + cal(suf[r+1]);
sum -= cal(suf[l]);
suf[l] += v;
sum += cal(suf[l]);
if(r+1 <= n){
sum -= cal(suf[r+1]);
suf[r+1] -= v;
sum += cal(suf[r+1]);
}
cout << sum << 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... |