답안 #378346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378346 2021-03-16T14:08:47 Z astoria Snowball (JOI21_ho_t2) C++14
100 / 100
148 ms 12260 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
const int N=2e5+5,Q=2e5+5;
int n,q,x[N];
int pl[Q],pr[Q];
int reachL[N],reachR[N];

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>q;
	x[0]=-1e18-5e17; x[n+1]=1e18+5e17;
	for(int i=1; i<=n; i++) cin>>x[i];
	vector<int> seg;
	for(int i=0; i<=n; i++) seg.push_back(x[i+1]-x[i]);
	
	pl[0]=0; pr[0]=0; int po=0ll;
	for(int i=1; i<=q; i++){
		int v; cin>>v;
		po += v;
		pl[i]=min(pl[i-1],po);
		pr[i]=max(pr[i-1],po);
	}
	pl[q+1]=-4e18; pr[q+1]=4e18;
	
	reachL[1]=pl[q]; reachR[n]=pr[q];
	
	for(int lo=2; lo<=q; lo++){
		assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1]);
	}
	
	for(int i=1; i<n; i++){
		int len = seg[i];
		int lo=0,hi=q+1; //first pos where pl+pr >= len
		while(lo<hi){
			int mid=(lo+hi)>>1;
			if(pr[mid]-pl[mid] >= len) hi=mid;
			else lo=mid+1;
		}
		//cout<<lo<<endl;
		if(lo==q+1){
			reachR[i]=pr[q];
			reachL[i+1]=pl[q];
			continue;
		} //case where they never meet
		assert(lo!=0); //len is positive
		//assert(pl[lo]==pl[lo-1] || pr[lo]==pr[lo-1] || lo==q+1); //this statement is triggered. How? Oh, Q+1 so not really
		//assert(pl[lo]!=pl[lo-1] || pr[lo]!=pr[lo-1]);
		
		if(pl[lo]!=pl[lo-1]){
			reachR[i] = pr[lo-1];
			reachL[i+1] = - (len - pr[lo-1]); //note reachL is negative
			//cout<<"LEFTCAUSE"<<i<<endl;
		} //left caused the ending
		else{
			reachL[i+1] = pl[lo-1];
			reachR[i] = len + pl[lo-1]; //reachL is negative so it's subtraction
			//cout<<"RIGHTCAUSE"<<i<<endl;
		} //right caused the ending
	}
	for(int i=1; i<=n; i++){
		cout<<reachR[i]-reachL[i]<<'\n';
	}
	
	/*for(int i=0; i<=q+1; i++){
		cout<<pl[i]<<" "<<pr[i]<<endl;
	}*/
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 31 ms 3524 KB Output is correct
21 Correct 30 ms 4096 KB Output is correct
22 Correct 29 ms 3948 KB Output is correct
23 Correct 27 ms 4076 KB Output is correct
24 Correct 35 ms 4976 KB Output is correct
25 Correct 119 ms 12004 KB Output is correct
26 Correct 117 ms 12004 KB Output is correct
27 Correct 131 ms 11748 KB Output is correct
28 Correct 114 ms 11876 KB Output is correct
29 Correct 111 ms 11620 KB Output is correct
30 Correct 107 ms 11236 KB Output is correct
31 Correct 76 ms 10852 KB Output is correct
32 Correct 82 ms 10724 KB Output is correct
33 Correct 12 ms 2032 KB Output is correct
34 Correct 122 ms 12004 KB Output is correct
35 Correct 115 ms 11876 KB Output is correct
36 Correct 115 ms 12004 KB Output is correct
37 Correct 148 ms 11748 KB Output is correct
38 Correct 118 ms 11748 KB Output is correct
39 Correct 115 ms 11876 KB Output is correct
40 Correct 84 ms 11792 KB Output is correct
41 Correct 34 ms 4076 KB Output is correct
42 Correct 90 ms 10724 KB Output is correct
43 Correct 91 ms 12004 KB Output is correct
44 Correct 33 ms 3948 KB Output is correct
45 Correct 82 ms 11776 KB Output is correct
46 Correct 99 ms 12260 KB Output is correct
47 Correct 94 ms 12132 KB Output is correct
48 Correct 116 ms 12152 KB Output is correct