답안 #372226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
372226 2021-02-27T09:44:20 Z dolphingarlic Snowball (JOI21_ho_t2) C++14
100 / 100
980 ms 63008 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll INF = 1e18;

int n, q, l1[200002], r1[200002], l2[200002], r2[200002];
vector<int> check_mn[200002], check_mx[200002];
ll x[200002], w[200002], ans_mn[200002], ans_mx[200002];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		l1[i] = l2[i] = 1;
		r1[i] = r2[i] = q;
	}
	x[0] = -INF, x[n + 1] = INF;
	for (int i = 1; i <= q; i++) cin >> w[i];
	for (int _ = 0; _ < 20; _++) {
		for (int i = 1; i <= n; i++) {
			int mid1 = (l1[i] + r1[i]) / 2;
			int mid2 = (l2[i] + r2[i]) / 2;
			check_mn[mid1].push_back(i);
			check_mx[mid2].push_back(i);
		}
		ll mn = 0, mx = 0, curr = 0;
		for (int i = 1; i <= q; i++) {
			curr += w[i];
			mn = min(mn, curr);
			mx = max(mx, curr);
			for (int j : check_mn[i]) {
				ll curr = x[j] + mn, to_left = x[j - 1] + mx;
				ans_mn[j] = max(ans_mn[j], x[j] - max(curr, to_left));
				if (curr <= to_left) r1[j] = i;
				else l1[j] = i + 1;
			}
			check_mn[i].clear();
			for (int j : check_mx[i]) {
				ll curr = x[j] + mx, to_right = x[j + 1] + mn;
				ans_mx[j] = max(ans_mx[j], min(curr, to_right) - x[j]);
				if (curr >= to_right) r2[j] = i;
				else l2[j] = i + 1;
			}
			check_mx[i].clear();
		}
	}
	for (int i = 1; i <= n; i++) cout << ans_mn[i] + ans_mx[i] << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9984 KB Output is correct
2 Correct 8 ms 9836 KB Output is correct
3 Correct 9 ms 9976 KB Output is correct
4 Correct 10 ms 10220 KB Output is correct
5 Correct 10 ms 10220 KB Output is correct
6 Correct 11 ms 10368 KB Output is correct
7 Correct 12 ms 10220 KB Output is correct
8 Correct 12 ms 10220 KB Output is correct
9 Correct 12 ms 10220 KB Output is correct
10 Correct 9 ms 10092 KB Output is correct
11 Correct 9 ms 10092 KB Output is correct
12 Correct 7 ms 9836 KB Output is correct
13 Correct 7 ms 9836 KB Output is correct
14 Correct 7 ms 9836 KB Output is correct
15 Correct 10 ms 10220 KB Output is correct
16 Correct 10 ms 10220 KB Output is correct
17 Correct 9 ms 10092 KB Output is correct
18 Correct 7 ms 9836 KB Output is correct
19 Correct 9 ms 10092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9984 KB Output is correct
2 Correct 8 ms 9836 KB Output is correct
3 Correct 9 ms 9976 KB Output is correct
4 Correct 10 ms 10220 KB Output is correct
5 Correct 10 ms 10220 KB Output is correct
6 Correct 11 ms 10368 KB Output is correct
7 Correct 12 ms 10220 KB Output is correct
8 Correct 12 ms 10220 KB Output is correct
9 Correct 12 ms 10220 KB Output is correct
10 Correct 9 ms 10092 KB Output is correct
11 Correct 9 ms 10092 KB Output is correct
12 Correct 7 ms 9836 KB Output is correct
13 Correct 7 ms 9836 KB Output is correct
14 Correct 7 ms 9836 KB Output is correct
15 Correct 10 ms 10220 KB Output is correct
16 Correct 10 ms 10220 KB Output is correct
17 Correct 9 ms 10092 KB Output is correct
18 Correct 7 ms 9836 KB Output is correct
19 Correct 9 ms 10092 KB Output is correct
20 Correct 59 ms 11368 KB Output is correct
21 Correct 49 ms 11520 KB Output is correct
22 Correct 50 ms 11500 KB Output is correct
23 Correct 56 ms 12524 KB Output is correct
24 Correct 133 ms 19564 KB Output is correct
25 Correct 884 ms 62444 KB Output is correct
26 Correct 868 ms 62584 KB Output is correct
27 Correct 945 ms 62352 KB Output is correct
28 Correct 875 ms 62296 KB Output is correct
29 Correct 882 ms 61796 KB Output is correct
30 Correct 468 ms 55384 KB Output is correct
31 Correct 269 ms 52376 KB Output is correct
32 Correct 231 ms 48280 KB Output is correct
33 Correct 56 ms 14956 KB Output is correct
34 Correct 609 ms 58096 KB Output is correct
35 Correct 708 ms 58968 KB Output is correct
36 Correct 980 ms 63008 KB Output is correct
37 Correct 885 ms 62168 KB Output is correct
38 Correct 816 ms 61912 KB Output is correct
39 Correct 468 ms 56664 KB Output is correct
40 Correct 250 ms 54564 KB Output is correct
41 Correct 53 ms 11372 KB Output is correct
42 Correct 193 ms 48280 KB Output is correct
43 Correct 223 ms 49220 KB Output is correct
44 Correct 53 ms 11372 KB Output is correct
45 Correct 227 ms 49092 KB Output is correct
46 Correct 227 ms 49476 KB Output is correct
47 Correct 228 ms 49348 KB Output is correct
48 Correct 222 ms 49220 KB Output is correct