Submission #33259

#TimeUsernameProblemLanguageResultExecution timeMemory
33259minkankFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
243 ms3576 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, m, s, t;
long long ans = 0, a[N];

int main() {
	scanf("%d %d %d %d", &n, &m, &t, &s);
	for(int i = 0; i <= n; ++i) scanf("%lld", &a[i]);
	for(int i = n; i >= 1; --i) {
		a[i] -= a[i - 1];
		if(a[i] > 0) ans -= a[i] * t;
		else ans += -a[i] * s;
	}
	for(int i = 0; i < m; ++i) {
		int l, r, x; scanf("%d %d %d", &l, &r, &x);
		if(a[l] > 0) ans += a[l] * t;
		else ans -= -a[l] * s;
		a[l] += x;
		if(a[l] > 0) ans -= a[l] * t;
		else ans += -a[l] * s;
		if(r != n) {
			if(a[r + 1] > 0) ans += a[r + 1] * t;
			else ans -= -a[r + 1] * s;
			a[r + 1] -= x; 
			if(a[r + 1] > 0) ans -= a[r + 1] * t;
			else ans += -a[r + 1] * s;
		}
		cout << ans << '\n';
	}
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:10:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &n, &m, &t, &s);
                                      ^
foehn_phenomena.cpp:11:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i <= n; ++i) scanf("%lld", &a[i]);
                                                  ^
foehn_phenomena.cpp:18:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int l, r, x; scanf("%d %d %d", &l, &r, &x);
                                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...