Submission #154326

#TimeUsernameProblemLanguageResultExecution timeMemory
154326ivandasfsFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
241 ms11652 KiB
#include <iostream>

using namespace std;

typedef long long ll;

ll n, q, s, t;

ll a[200005];
ll sol;

ll calc(ll x) {
	if (x<0) {
		return (-x) * t;
	}
	return (-x) * s;
}

void update(int pos, int x) {
	if (pos<0 or pos>=n-1) return ;
	ll newa = a[pos]+x;
	ll O = calc(a[pos]);
	ll N = calc(newa);
	sol = sol - O + N;
	a[pos] += x;
}

int main() {
	scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
	n++;
	ll l = 0;
	for (int i=0 ; i<n ; i++) {
		ll x;
		scanf("%lld", &x);
		if (i) {
			a[i-1] = x-l;
			sol += calc(x-l);
		}
		l = x;
	}
//	printf("sol = %lld\n", sol);
	for (int i=0 ; i<q ; i++) {
		int l, r;
		ll x;
		scanf("%d%d%lld", &l, &r, &x);
		l--;
		update(l, x);
		update(r, -x);
		printf("%lld\n", sol);
	}
	return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &x);
   ~~~~~^~~~~~~~~~~~
foehn_phenomena.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%lld", &l, &r, &x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...