답안 #921435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921435 2024-02-03T20:48:22 Z TAhmed33 Snowball (JOI21_ho_t2) C++
100 / 100
99 ms 15444 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
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';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 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 2 ms 4444 KB Output is correct
10 Correct 1 ms 4440 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 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 2 ms 4444 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 2 ms 4444 KB Output is correct
10 Correct 1 ms 4440 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 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 19 ms 6748 KB Output is correct
21 Correct 18 ms 6568 KB Output is correct
22 Correct 19 ms 7068 KB Output is correct
23 Correct 17 ms 6748 KB Output is correct
24 Correct 25 ms 6996 KB Output is correct
25 Correct 97 ms 9812 KB Output is correct
26 Correct 98 ms 9808 KB Output is correct
27 Correct 91 ms 9560 KB Output is correct
28 Correct 94 ms 9524 KB Output is correct
29 Correct 94 ms 9360 KB Output is correct
30 Correct 86 ms 9208 KB Output is correct
31 Correct 60 ms 8528 KB Output is correct
32 Correct 43 ms 8500 KB Output is correct
33 Correct 9 ms 4956 KB Output is correct
34 Correct 98 ms 9672 KB Output is correct
35 Correct 92 ms 9552 KB Output is correct
36 Correct 95 ms 9808 KB Output is correct
37 Correct 99 ms 9648 KB Output is correct
38 Correct 92 ms 9552 KB Output is correct
39 Correct 89 ms 9552 KB Output is correct
40 Correct 54 ms 9412 KB Output is correct
41 Correct 19 ms 6744 KB Output is correct
42 Correct 44 ms 11860 KB Output is correct
43 Correct 56 ms 14932 KB Output is correct
44 Correct 20 ms 9296 KB Output is correct
45 Correct 50 ms 13140 KB Output is correct
46 Correct 56 ms 15188 KB Output is correct
47 Correct 57 ms 15440 KB Output is correct
48 Correct 58 ms 15444 KB Output is correct