Submission #921434

# Submission time Handle Problem Language Result Execution time Memory
921434 2024-02-03T20:48:02 Z TAhmed33 Snowball (JOI21_ho_t2) C++
33 / 100
112 ms 13756 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e16;
const int MAXN = 2e5 + 25;
ll a[MAXN], n, q;
ll pref[MAXN], u[MAXN], mx[MAXN], mn[MAXN];
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= q; i++) {
		cin >> u[i]; u[i] += u[i - 1];
		mx[i] = max(u[i], mx[i - 1]);
		mn[i] = min(u[i], mn[i - 1]);
	}
	a[0] = -inf; a[n + 1] = inf;
	for (int i = 1; i <= n; i++) {
		ll l = 1, r = q, ans1 = 0;
		ll tl = a[i - 1], tr = a[i + 1];
		while (l <= r) {
			ll mid = (l + r) >> 1;
			if (tl + mx[mid] < a[i] + mn[mid]) {
				l = mid + 1; ans1 = mid;
			} else {
				r = mid - 1;
			}
		}
		l = 1, r = q; ll ans2 = 0;
		while (l <= r) {
			ll mid = (l + r) >> 1;
			if (a[i] + mx[mid] < tr + mn[mid]) {
				l = mid + 1; ans2 = mid;
			} else {
				r = mid - 1;
			}
		}
		ll weight = -mn[ans1] + mx[ans2];
		//cout << tl + mx[ans1] << " " << a[i] + mn[ans1] << ": " << a[i] + mx[ans2] << " " << tr + mn[ans2] << '\n';
		if (ans1 < q) {
			ll x = tl + mx[ans1], y = a[i] + mn[ans1];
			if (u[ans1 + 1] < 0) {
				weight += y - x;
			}
		}
		if (ans2 < q) {
			ll x = a[i] + mx[ans2], y = tr + mn[ans2];
			if (u[ans2 + 1] > 0) {
				weight += y - x;
			}
		}
		cout << weight << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4656 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 2 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4656 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 20 ms 8796 KB Output is correct
21 Correct 20 ms 8540 KB Output is correct
22 Correct 18 ms 8540 KB Output is correct
23 Correct 17 ms 8284 KB Output is correct
24 Correct 24 ms 8632 KB Output is correct
25 Correct 104 ms 13684 KB Output is correct
26 Correct 93 ms 13396 KB Output is correct
27 Correct 95 ms 13144 KB Output is correct
28 Correct 109 ms 13328 KB Output is correct
29 Correct 94 ms 12624 KB Output is correct
30 Correct 91 ms 12176 KB Output is correct
31 Correct 50 ms 11568 KB Output is correct
32 Correct 54 ms 11600 KB Output is correct
33 Correct 9 ms 5464 KB Output is correct
34 Correct 112 ms 13732 KB Output is correct
35 Correct 93 ms 13340 KB Output is correct
36 Correct 93 ms 13380 KB Output is correct
37 Correct 100 ms 13756 KB Output is correct
38 Correct 96 ms 13012 KB Output is correct
39 Correct 92 ms 13136 KB Output is correct
40 Correct 56 ms 13240 KB Output is correct
41 Incorrect 20 ms 9432 KB Output isn't correct
42 Halted 0 ms 0 KB -