답안 #396926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396926 2021-05-01T01:52:23 Z AQT Snowball (JOI21_ho_t2) C++14
100 / 100
141 ms 15300 KB
#include <bits/stdc++.h>

using namespace std;

int N, Q;
long long x[200005];
long long w[200005];
long long d[200005];
long long lft[200005], rht[200005];
long long ans[200005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> Q;
	for(int i = 1; i <= N; i++){
		cin >> x[i];
	}
	for(int i = 1; i <= Q; i++){
		cin >> d[i];
		d[i] += d[i-1];
	}
	for(int i = 1; i <= Q; i++){
		if(d[i] < 0){
			rht[i] = -d[i];
		}
		else{
			lft[i] = d[i];
		}
		rht[i] = max(rht[i], rht[i-1]);
		lft[i] = max(lft[i], lft[i-1]);
	}
	ans[1] = rht[Q];
	ans[N] += lft[Q];
	sort(x+1, x+1+N);
	for(int i = 1; i < N; i++){
		if(lft[Q] + rht[Q] > x[i + 1] - x[i]){
			int l = 1, r = Q, k = 0;
			while(l <= r){
				int mid = (l + r)/2;
				if(lft[mid] + rht[mid] < x[i + 1] - x[i]){
					l = mid + 1;
				}
				else{
					r = mid - 1;
					k = mid;
				}
			}
			ans[i] += lft[k-1];
			ans[i+1] += rht[k-1];
			if(lft[k-1] != lft[k]){
				ans[i] += x[i + 1] - x[i] - lft[k-1] - rht[k-1];
			}
			else{
				ans[i+1] += x[i+1] - x[i] - lft[k-1] - rht[k-1];
			}
		}
		else{
			ans[i] += lft[Q];
			ans[i+1] += rht[Q];
		}
	}
	for(int i = 1; i <= N; i++){
		cout << ans[i];
		if(i != N){
			cout << "\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 32 ms 7108 KB Output is correct
21 Correct 31 ms 6908 KB Output is correct
22 Correct 30 ms 6724 KB Output is correct
23 Correct 28 ms 6596 KB Output is correct
24 Correct 43 ms 7076 KB Output is correct
25 Correct 120 ms 13380 KB Output is correct
26 Correct 124 ms 13364 KB Output is correct
27 Correct 141 ms 13024 KB Output is correct
28 Correct 120 ms 13124 KB Output is correct
29 Correct 122 ms 12612 KB Output is correct
30 Correct 126 ms 12068 KB Output is correct
31 Correct 81 ms 11468 KB Output is correct
32 Correct 70 ms 11640 KB Output is correct
33 Correct 12 ms 1720 KB Output is correct
34 Correct 126 ms 13896 KB Output is correct
35 Correct 128 ms 13124 KB Output is correct
36 Correct 122 ms 13376 KB Output is correct
37 Correct 121 ms 13124 KB Output is correct
38 Correct 117 ms 13020 KB Output is correct
39 Correct 117 ms 13180 KB Output is correct
40 Correct 96 ms 13224 KB Output is correct
41 Correct 34 ms 7708 KB Output is correct
42 Correct 73 ms 11656 KB Output is correct
43 Correct 94 ms 14916 KB Output is correct
44 Correct 35 ms 7624 KB Output is correct
45 Correct 79 ms 13124 KB Output is correct
46 Correct 101 ms 14988 KB Output is correct
47 Correct 100 ms 15300 KB Output is correct
48 Correct 105 ms 15300 KB Output is correct