Submission #977843

#TimeUsernameProblemLanguageResultExecution timeMemory
977843SmuggingSpunFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
117 ms11620 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
typedef long long ll;
const int lim = 2e5 + 5;
int n, q, s, t;
ll ans = 0, bit[lim];
void update(int p, int x){
	for(; p <= n; p += p & -p){
		bit[p] += x;
	}
}
ll get(int p){
	ll ans = 0;
	for(; p > 0; p -= p & -p){
		ans += bit[p];
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> q >> s >> t;
	int x;
	cin >> x;
	for(int i = 1, pre = 0; i <= n; i++, pre = x){
		cin >> x;
		update(i, x - pre);
		if(pre < x){
			ans -= 1LL * s * (x - pre);
		}
		else{
			ans += 1LL * t * (pre - x);
		}
	}
	for(int _ = 0; _ < q; _++){
		int l, r, x;
		cin >> l >> r >> x;
		ll d = get(l - 1) - get(l);
		if(d < 0){
			ans += 1LL * s * -d;
		}
		else{
			ans -= 1LL * t * d;
		}
		if(r < n){
			if((d = get(r) - get(r + 1)) < 0){
				ans += 1LL * s * -d;
			}
			else{
				ans -= 1LL * t * d;
			}
		}
		update(l, x);
		update(r + 1, -x);
		if((d = get(l - 1) - get(l)) < 0){
			ans -= 1LL * s * -d;
		}
		else{
			ans += 1LL * t * d;
		}
		if(r < n){
			if((d = get(r) - get(r + 1)) < 0){
				ans -= 1LL * s * -d;
			}
			else{
				ans += 1LL * t * d;
			}
		}
		cout << ans << "\n";
	}
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:23:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...