Submission #991139

# Submission time Handle Problem Language Result Execution time Memory
991139 2024-06-01T11:53:09 Z horezushol Foehn Phenomena (JOI17_foehn_phenomena) C++14
100 / 100
369 ms 19764 KB
#include<bits/stdc++.h>

const char nl = '\n';

using namespace std;
using ll = long long;


ll s, t;
struct Segtree {
	struct node {
		ll le, ri, wd; // leftest element, rightest element, power of wind
	};
	vector<ll> tree;
	vector<ll> sh;
	vector<ll> a;

	ll sz = 1;
	ll nope = 0;
	void init(ll n) {
		while (sz < n) {
			sz *= 2;
		}
		tree.assign(2*sz+1, 0);
		sh.assign(2*sz+1, 0);
		a.assign(n+10, 0);
	}

	void create(ll n) {
		for (ll i = 0, lf = sz-1; i <= n; i ++, lf ++) {
			tree[lf] = a[i];
		}
	}

	void build(ll x, ll lx, ll rx) {
		if (rx - lx == 1) {
			return ;
		}
		ll mid = (lx + rx) / 2;
		build(2*x+1, lx, mid);
		build(2*x+2, mid, rx);
		tree[x] = tree[2*x+1] + tree[2*x+2];
	}


	void build() {
		build(0, 0, sz);
	}

	void push(ll x, ll lx, ll rx) {
		if (sh[x] == nope) return ;
		if (rx - lx == 1) return ;
		sh[2*x+1] += sh[x];
		tree[2*x+1] += sh[x];
		sh[2*x+2] += sh[x];
		tree[2*x+2] += sh[x];
		sh[x] = nope;
	}

	void update(ll l, ll r, ll v, ll x, ll lx, ll rx) {
		push(x, lx, rx);
		if (lx >= r || rx <= l) {
			return ;
		}
		if (l <= lx && rx <= r) {
			sh[x] += v;
			push(x, lx, rx);
			tree[x] += v;
			return ;
		}
		ll mid = (lx + rx) / 2;
		update(l, r, v, 2*x+1, lx, mid);
		update(l, r, v, 2*x+2, mid, rx);
		tree[x] = tree[2*x+1] + tree[2*x+2];
	}

	void update(ll l, ll r, ll v) {
		update(l, r, v, 0, 0, sz);
	}

	ll get(ll i, ll x, ll lx, ll rx) {
		push(x, lx, rx);
		if (rx - lx == 1) {
			return tree[x];
		}
		ll mid = (lx + rx) / 2;
		if (i < mid) {
			return get(i, 2*x+1, lx, mid);
		} else {
			return get(i, 2*x+2, mid, rx);
		}
	}

	ll get(ll i) {
		return get(i, 0, 0, sz);
	}

	void debug() {
		for (ll i = 0; i < 2*sz-1; i ++) {
			cout << i << ": " << tree[i] << nl;
		}
	}
};

ll wind(ll x, ll y) {
    return (x < y ? s * (x - y) : t * (x - y));
}

void solve() {
	ll n, q;
	cin >> n >> q >> s >> t;
	Segtree sg;
	n ++;
	sg.init(n);
	for (ll i = 0; i < n; i ++) {
		cin >> sg.a[i];
	}
	sg.create(n);
	sg.build();
	ll res = 0;
	for (ll i = 0; i < n-1; i ++) {
		res += wind(sg.a[i], sg.a[i+1]);
	}
	for (ll i = 0; i < q; i ++) {
		ll l, r, v;
		cin >> l >> r >> v;
		r ++;
		res -= wind(sg.get(l-1), sg.get(l));
		if (r != n) {
			res -= wind(sg.get(r-1), sg.get(r));
		}
		sg.update(l, r, v);
		res += wind(sg.get(l-1), sg.get(l));
		if (r != n) {
			res += wind(sg.get(r-1), sg.get(r));
		}	
		cout << res << nl;	
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll tst = 1;
	// cin >> tst;
	while (tst --) {
		solve();
		cout << nl;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 464 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 16980 KB Output is correct
2 Correct 350 ms 17520 KB Output is correct
3 Correct 330 ms 18256 KB Output is correct
4 Correct 335 ms 17580 KB Output is correct
5 Correct 327 ms 18632 KB Output is correct
6 Correct 177 ms 17744 KB Output is correct
7 Correct 161 ms 17732 KB Output is correct
8 Correct 277 ms 18516 KB Output is correct
9 Correct 304 ms 18772 KB Output is correct
10 Correct 298 ms 17644 KB Output is correct
11 Correct 163 ms 17648 KB Output is correct
12 Correct 195 ms 18492 KB Output is correct
13 Correct 181 ms 18460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 3 ms 464 KB Output is correct
11 Correct 3 ms 604 KB Output is correct
12 Correct 3 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 345 ms 16980 KB Output is correct
23 Correct 350 ms 17520 KB Output is correct
24 Correct 330 ms 18256 KB Output is correct
25 Correct 335 ms 17580 KB Output is correct
26 Correct 327 ms 18632 KB Output is correct
27 Correct 177 ms 17744 KB Output is correct
28 Correct 161 ms 17732 KB Output is correct
29 Correct 277 ms 18516 KB Output is correct
30 Correct 304 ms 18772 KB Output is correct
31 Correct 298 ms 17644 KB Output is correct
32 Correct 163 ms 17648 KB Output is correct
33 Correct 195 ms 18492 KB Output is correct
34 Correct 181 ms 18460 KB Output is correct
35 Correct 332 ms 16980 KB Output is correct
36 Correct 345 ms 18672 KB Output is correct
37 Correct 334 ms 19284 KB Output is correct
38 Correct 357 ms 19268 KB Output is correct
39 Correct 369 ms 19024 KB Output is correct
40 Correct 334 ms 19236 KB Output is correct
41 Correct 351 ms 19028 KB Output is correct
42 Correct 319 ms 19024 KB Output is correct
43 Correct 368 ms 18516 KB Output is correct
44 Correct 351 ms 18768 KB Output is correct
45 Correct 336 ms 18660 KB Output is correct
46 Correct 346 ms 19764 KB Output is correct
47 Correct 164 ms 18256 KB Output is correct
48 Correct 130 ms 18292 KB Output is correct
49 Correct 358 ms 17408 KB Output is correct
50 Correct 161 ms 18260 KB Output is correct
51 Correct 214 ms 18496 KB Output is correct
52 Correct 189 ms 18420 KB Output is correct