Submission #960931

# Submission time Handle Problem Language Result Execution time Memory
960931 2024-04-11T09:05:20 Z happy_node Snowball (JOI21_ho_t2) C++17
100 / 100
94 ms 15444 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MX=2e5+5;

int N,Q;
ll X[MX],W[MX],ans[MX],L[MX],R[MX];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin>>N>>Q;
	for(int i=1;i<=N;i++) cin>>X[i];
	ll sum=0;
	for(int i=1;i<=Q;i++) {
		cin>>W[i];
		sum+=W[i];
		L[i]=min(L[i-1],sum);
		R[i]=max(R[i-1],sum);
	}

	for(int i=1;i<N;i++) {
		int l=0,r=Q,res=0;
		while(l<=r) {
			int m=(l+r)/2;
			if(R[m]-L[m]<X[i+1]-X[i]) {
				l=m+1,res=m;
 			} else {
 				r=m-1;
 			}
		}
		ans[i]+=R[res];
		ans[i+1]-=L[res];
		if(res==Q) continue;
		
		if(W[res+1]>0) 
			ans[i]+=(X[i+1]-X[i])-(R[res]-L[res]);
		else
			ans[i+1]+=(X[i+1]-X[i])-(R[res]-L[res]);
	}

	ans[1]-=L[Q];
	ans[N]+=R[Q];

	for(int i=1;i<=N;i++) cout<<ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2524 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2528 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 2 ms 2524 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2528 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 26 ms 9040 KB Output is correct
21 Correct 24 ms 8540 KB Output is correct
22 Correct 22 ms 8536 KB Output is correct
23 Correct 17 ms 8260 KB Output is correct
24 Correct 28 ms 8648 KB Output is correct
25 Correct 94 ms 13392 KB Output is correct
26 Correct 88 ms 13456 KB Output is correct
27 Correct 93 ms 13068 KB Output is correct
28 Correct 76 ms 13124 KB Output is correct
29 Correct 73 ms 12672 KB Output is correct
30 Correct 75 ms 12424 KB Output is correct
31 Correct 53 ms 11528 KB Output is correct
32 Correct 42 ms 11688 KB Output is correct
33 Correct 11 ms 3420 KB Output is correct
34 Correct 81 ms 13872 KB Output is correct
35 Correct 74 ms 13232 KB Output is correct
36 Correct 75 ms 13392 KB Output is correct
37 Correct 78 ms 13176 KB Output is correct
38 Correct 76 ms 13064 KB Output is correct
39 Correct 73 ms 13284 KB Output is correct
40 Correct 52 ms 13140 KB Output is correct
41 Correct 28 ms 9380 KB Output is correct
42 Correct 47 ms 11780 KB Output is correct
43 Correct 55 ms 15008 KB Output is correct
44 Correct 20 ms 9304 KB Output is correct
45 Correct 48 ms 13140 KB Output is correct
46 Correct 54 ms 15020 KB Output is correct
47 Correct 56 ms 15444 KB Output is correct
48 Correct 56 ms 15440 KB Output is correct