Created
February 13, 2017 14:22
-
-
Save rogerioagjr/e7a6ed6d99625efc26eb892a89fecaf5 to your computer and use it in GitHub Desktop.
Foehn Phenomena
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define MAXN 200200 | |
typedef long long ll; | |
ll delta[MAXN], s, t, last, pos, neg; | |
int n, q; | |
void upd(int p, ll d){ | |
if(p<1 or p>n) return; | |
if(delta[p]>0) pos-=delta[p]; | |
else neg+=delta[p]; | |
delta[p]+=d; | |
if(delta[p]>0) pos+=delta[p]; | |
else neg-=delta[p]; | |
} | |
int main(){ | |
cin >> n >> q >> s >> t; | |
for(int i=0;i<=n;i++){ | |
cin >> delta[i]; | |
delta[i]-=last; | |
if(delta[i]>0) pos+=delta[i]; | |
else neg-=delta[i]; | |
last+=delta[i]; | |
} | |
for(int i=0;i<q;i++){ | |
int l, r; | |
ll d; | |
cin >> l >> r >> d; | |
upd(l,d), upd(r+1,-d); | |
cout << ll(neg*t-pos*s) << "\n"; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment