Submission #1018255

#TimeUsernameProblemLanguageResultExecution timeMemory
1018255vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
75 ms13148 KiB
#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define pp pop_back
#define int int64_t
#define sc second
#define fr first
using namespace std;
const int T=1e18+7, K=1e9+7;
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q, s, t, i, j, l, r, x, ans=0;
	cin >> n >> q >> s >> t;
	vector <int> v(n+1), d(n+1);
	cin >> v[0];
//	1 2

//	0 4 1 8
//	-4 2-5
	
//	0 6 3 8
//	-6 0-5
//	
//	0 4 3 8
//	-4-2-7

//	8 1 1 2
//	0 5 9|3 -2 9 4|6 7
//	-5 -9 3 13 2 12 10 9

//	0 5 9|8 3 14 9|6 7
//	-5 -9 -7 3 -8 2 8 7
	for (i=1; i<=n; i++) {
		cin >> v[i];
		d[i]=v[i]-v[i-1];
		if (d[i]>0) {
			ans-=d[i]*s;
		}
		else {
			ans-=d[i]*t;
		}
	}
	while (q--) {
		cin >> l >> r >> x;
		if (d[l]>0) {
			ans+=d[l]*s;
		}
		else {
			ans+=d[l]*t;
		}
		if (r+1<=n) {
			if (d[r+1]>0) {
				ans+=d[r+1]*s;
			}
			else {
				ans+=d[r+1]*t;
			}
		}
		d[l]+=x;
		if (r+1<=n) {
			d[r+1]-=x;
		}
		if (d[l]>0) {
			ans-=d[l]*s;
		}
		else {
			ans-=d[l]*t;
		}
		if (r+1<=n) {
			if (d[r+1]>0) {
				ans-=d[r+1]*s;
			}
			else {
				ans-=d[r+1]*t;
			}
		}
		cout << ans << '\n';
	}
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:13:21: warning: unused variable 'j' [-Wunused-variable]
   13 |  int n, q, s, t, i, j, l, r, x, ans=0;
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...