Submission #528114

# Submission time Handle Problem Language Result Execution time Memory
528114 2022-02-19T09:53:24 Z Jasiekstrz Snowball (JOI21_ho_t2) C++17
100 / 100
127 ms 13768 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=2e5;
const long long INF=1e18L+7;
long long x[N+10];
long long w[N+10];
pair<long long,long long> seg[N+10];
int bs(long long d,int q)
{
	int bg=0,en=q;
	while(bg<en)
	{
		int mid=(bg+en+1)/2;
		if(seg[mid].se-seg[mid].fi<=d)
			bg=mid;
		else
			en=mid-1;
	}
	return bg;
}
long long solver(long long d,int q)
{
	int it=bs(d,q);
	if(it==q)
		return -seg[it].fi;
	if(w[it+1]<0)
		return d-seg[it].se;
	return -seg[it].fi;
}
long long solvel(long long d,int q)
{
	int it=bs(d,q);
	if(it==q)
		return seg[it].se;
	if(w[it+1]>0)
		return d+seg[it].fi;
	return seg[it].se;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	for(int i=1;i<=n;i++)
		cin>>x[i];
	seg[0]={0,0};
	long long pos=0;
	for(int i=1;i<=q;i++)
	{
		cin>>w[i];
		pos+=w[i];
		seg[i].fi=min(seg[i-1].fi,pos);
		seg[i].se=max(seg[i-1].se,pos);
	}
	x[0]=-INF;
	x[n+1]=INF;
	for(int i=1;i<=n;i++)
		cout<<solver(x[i]-x[i-1],q)+solvel(x[i+1]-x[i],q)<<"\n";
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 464 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 368 KB Output is correct
20 Correct 25 ms 7108 KB Output is correct
21 Correct 25 ms 6852 KB Output is correct
22 Correct 24 ms 6664 KB Output is correct
23 Correct 22 ms 6596 KB Output is correct
24 Correct 30 ms 6952 KB Output is correct
25 Correct 121 ms 11820 KB Output is correct
26 Correct 123 ms 11716 KB Output is correct
27 Correct 122 ms 11440 KB Output is correct
28 Correct 122 ms 11544 KB Output is correct
29 Correct 120 ms 11052 KB Output is correct
30 Correct 111 ms 10492 KB Output is correct
31 Correct 73 ms 9932 KB Output is correct
32 Correct 61 ms 10120 KB Output is correct
33 Correct 11 ms 1508 KB Output is correct
34 Correct 123 ms 12348 KB Output is correct
35 Correct 123 ms 11592 KB Output is correct
36 Correct 127 ms 11860 KB Output is correct
37 Correct 124 ms 11592 KB Output is correct
38 Correct 118 ms 11388 KB Output is correct
39 Correct 116 ms 11592 KB Output is correct
40 Correct 76 ms 11592 KB Output is correct
41 Correct 27 ms 7744 KB Output is correct
42 Correct 61 ms 10108 KB Output is correct
43 Correct 88 ms 13292 KB Output is correct
44 Correct 30 ms 7580 KB Output is correct
45 Correct 69 ms 11552 KB Output is correct
46 Correct 92 ms 13516 KB Output is correct
47 Correct 91 ms 13692 KB Output is correct
48 Correct 90 ms 13768 KB Output is correct