답안 #696663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696663 2023-02-07T03:16:05 Z yaufung Snowball (JOI21_ho_t2) C++17
100 / 100
122 ms 15360 KB
#include <bits/stdc++.h>
using namespace std;
#define LL long long

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	vector<LL> a(n + 5), Q(q + 5), ans(n + 5);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= q; i++) {
		cin >> Q[i];
	}
	vector<LL> l(q + 5), r(q + 5);
	LL p = 0;
	l[0] = r[0] = 0;
	for (int i = 1; i <= q; i++) {
		p += Q[i];
		r[i] = max(r[i - 1], -p);
		l[i] = max(l[i - 1], p);
	}
	ans[1] += r[q];
	ans[n] += l[q];
	for (int i = 1; i < n; i++) {
		LL diff = a[i + 1] - a[i];
		int bot = 0, top = q, mid;
		while (bot <= top) {
			mid = (bot + top) / 2;
			if (l[mid] + r[mid] >= diff) {
				top = mid - 1;				
			}
			else bot = mid + 1;
		}
		ans[i] += l[top];
		ans[i + 1] += r[top];
		LL remain = diff - l[top] - r[top];
		if (top < q) {
			if (l[top + 1] > l[top]) ans[i] += remain;
			else ans[i + 1] += remain;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << "\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 408 KB Output is correct
9 Correct 2 ms 400 KB Output is correct
10 Correct 2 ms 400 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 416 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 356 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 408 KB Output is correct
9 Correct 2 ms 400 KB Output is correct
10 Correct 2 ms 400 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 416 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 38 ms 7108 KB Output is correct
21 Correct 29 ms 6864 KB Output is correct
22 Correct 25 ms 6744 KB Output is correct
23 Correct 24 ms 6556 KB Output is correct
24 Correct 41 ms 7076 KB Output is correct
25 Correct 101 ms 13416 KB Output is correct
26 Correct 96 ms 13316 KB Output is correct
27 Correct 106 ms 13064 KB Output is correct
28 Correct 104 ms 13192 KB Output is correct
29 Correct 97 ms 12680 KB Output is correct
30 Correct 88 ms 12108 KB Output is correct
31 Correct 65 ms 11512 KB Output is correct
32 Correct 62 ms 11696 KB Output is correct
33 Correct 9 ms 1604 KB Output is correct
34 Correct 109 ms 13700 KB Output is correct
35 Correct 95 ms 13112 KB Output is correct
36 Correct 105 ms 13400 KB Output is correct
37 Correct 122 ms 13160 KB Output is correct
38 Correct 103 ms 13064 KB Output is correct
39 Correct 99 ms 13184 KB Output is correct
40 Correct 74 ms 13252 KB Output is correct
41 Correct 31 ms 7632 KB Output is correct
42 Correct 57 ms 11664 KB Output is correct
43 Correct 91 ms 14984 KB Output is correct
44 Correct 34 ms 7508 KB Output is correct
45 Correct 70 ms 13132 KB Output is correct
46 Correct 92 ms 15108 KB Output is correct
47 Correct 79 ms 15296 KB Output is correct
48 Correct 79 ms 15360 KB Output is correct