# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
497641 | penguin133 | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 133 ms | 13044 KiB |
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
int ft[200005],n,q,s,t;
void update(int l, int r, int v){
r++;
for(;l<=n;l+=(l & -l))ft[l] += v;
for(;r<=n;r+=(r & -r))ft[r] -= v;
}
int query(int p){
int sum = 0;
for(;p;p-=(p & -p))sum += ft[p];
return sum;
}
int A[200005];
main(){
ios::sync_with_stdio(0);cin.tie(0);
int h,w,ans = 0;
cin >> n >> q >> s >> t;
for(int i=0;i<=n;i++){
cin >> A[i];
if(i == 0)continue;
if(A[i] > A[i-1])ans -= s * abs(A[i] - A[i-1]);
else ans += t * abs(A[i] - A[i-1]);
update(i,i,A[i]);
}
while(q--){
int l,r,v;
cin >> l>> r >> v;
int x = query(l) - query(l-1);
int y = 0;
if(r < n)y = query(r+1) - query(r);
update(l,r,v);
int x1 = query(l) - query(l-1);
if(x <= 0)ans -= t*(-x);
else ans += x*s;
if(x1 <= 0)ans -= t*x1;
else ans -= x1*s;
if(r != n){
int y1 = query(r+1) - query(r);
if(y <= 0)ans -= t*(-y);
else ans += s*y;
if(y1 <= 0)ans += t*(-y1);
else ans -= s*y1;
}
cout << ans << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |