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 ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
const ll N = 2e5+7;
ll n, m, r, s, u, v, o, f[N], a[N], ans = 0;
signed main(){
// freopen("PERFECT1.inp","r",stdin);
// freopen("PERFECT1.out","w",stdout);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> r >> s;
f(i,0,n){
cin >> a[i];
if(i){
f[i] = a[i]-a[i-1];
ans -= f[i] > 0 ? f[i]*r : f[i]*s;
}
}
while(m--){
cin >> u >> v >> o;
ans += f[u] > 0 ? f[u]*r : f[u]*s;
f[u] += o;
ans -= f[u] > 0 ? f[u]*r : f[u]*s;
if(v != n){
ans += f[v+1] > 0 ? f[v+1]*r : f[v+1]*s;
f[v+1] -= o;
ans -= f[v+1] > 0 ? f[v+1]*r : f[v+1]*s;
}
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... |