Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created February 13, 2017 14:22
Show Gist options
  • Save rogerioagjr/e7a6ed6d99625efc26eb892a89fecaf5 to your computer and use it in GitHub Desktop.
Save rogerioagjr/e7a6ed6d99625efc26eb892a89fecaf5 to your computer and use it in GitHub Desktop.
Foehn Phenomena
#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