Submission #224997

#TimeUsernameProblemLanguageResultExecution timeMemory
224997bharat2002Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
561 ms13208 KiB
/*input
3 0 1 2
0
6
3
8
1 2 2
1 1 -2
2 3 5
1 2 -1
1 3 5
*/
#include<bits/stdc++.h>
using namespace std;
const int N=2e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl 
//Trace prints the name of the variable and the value.
int arr[N], diff[N], s, t, n, q;
int cost(int x)
{
	if(x>0) return s*x;
	return t*x;
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int ans=0;cin>>n>>q>>s>>t;s*=-1;t*=-1;
	for(int i=0;i<=n;i++) cin>>arr[i];
	for(int i=1;i<=n;i++) {diff[i]=arr[i]-arr[i-1];
		ans+=cost(diff[i]);//cout<<diff[i]<<" "<<ans<<endl;
	}
//			cout<<ans<<endl;	
	while(q--)
	{
		int l, r, val;cin>>l>>r>>val;
		ans-=cost(diff[l]);diff[l]+=val;ans+=cost(diff[l]);
		if(r!=n) 
		{r++;ans-=cost(diff[r]);diff[r]-=val;ans+=cost(diff[r]);}
		cout<<ans<<endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...