답안 #601992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
601992 2022-07-22T13:14:19 Z ignus Snowball (JOI21_ho_t2) C++14
100 / 100
224 ms 14876 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	long long n, q;
	cin >> n >> q;
	vector<long long> a;
	for(long long i = 0; i < n; i++){
		long long t;
		cin >> t;
		a.push_back(t);
	}
	vector<long long> l={0};
	vector<long long> r={0};
	long long ll=-10, lr=-10, loc = 0, l1=0, r1=0;
	long long f = -1;
	for(long long i = 0; i < q; i++){
		long long t = 0;
		cin >> t;
		loc+=t;
		if(loc<l1){
			if(f==-1) f=0;
			l1=loc;
			if(ll>lr){
				l[l.size()-1]=loc;
			}else{
				l.push_back(loc);
			}
			ll=i;
		}
		if(loc>r1){
			if(f==-1) f=1;
			r1=loc;
			if(ll<lr){
				r[r.size()-1]=loc;
			}else{
				r.push_back(loc);
			}
			lr=i;
		}
	}
/*	for(long long i = 0; i < l.size(); i++){
		cout << l[i] << ' ';
	}
	cout << "\n\n";
	for(long long i = 0; i < r.size(); i++){
		cout << r[i] << ' ';
	}
	cout << "\n\n";*/
	long long ls[n], rs[n];
	ls[0]=a[0]+l1;
	rs[n-1]=a[n-1]+r1;
	for(long long i = 0; i < n-1; i++){
		if(a[i+1]-a[i]>r1-l1){
			rs[i]=a[i]+r1;
			ls[i+1]=a[i+1]+l1;
			continue;
		}
		long long lb=0, rb=l.size()+r.size()-1, mid;
		//l[(mid+1-f)/2]
		//r[(mid+f)/2]
		while(lb!=rb-1){
			mid=(lb+rb)/2;
			if(r[(mid+f)/2]-l[(mid+1-f)/2]<a[i+1]-a[i])lb=mid;
			else rb=mid;
		}
		//cout << lb << ' ' << rb << '\n';
		//cout << a[i]+r[(lb+f)/2] << ' ' << a[i+1]+l[(lb+1-f)/2] << "\n\n";
		if((lb+f+1)%2){
			rs[i]=a[i]+r[(lb+f)/2];
			ls[i+1]=a[i]+r[(lb+f)/2];
		}else{
			rs[i]=a[i+1]+l[(lb+1-f)/2];
			ls[i+1]=a[i+1]+l[(lb+1-f)/2];
		}
	}
//	cout << '\n';
	for(long long i = 0; i < n; i++){
		cout <<rs[i]-ls[i] << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 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 340 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 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 340 KB Output is correct
16 Correct 3 ms 312 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 308 KB Output is correct
20 Correct 83 ms 3356 KB Output is correct
21 Correct 75 ms 3140 KB Output is correct
22 Correct 88 ms 2924 KB Output is correct
23 Correct 85 ms 2788 KB Output is correct
24 Correct 71 ms 3512 KB Output is correct
25 Correct 197 ms 11576 KB Output is correct
26 Correct 185 ms 11356 KB Output is correct
27 Correct 191 ms 11012 KB Output is correct
28 Correct 193 ms 11124 KB Output is correct
29 Correct 172 ms 10152 KB Output is correct
30 Correct 171 ms 9076 KB Output is correct
31 Correct 163 ms 8496 KB Output is correct
32 Correct 138 ms 8608 KB Output is correct
33 Correct 21 ms 1360 KB Output is correct
34 Correct 216 ms 10672 KB Output is correct
35 Correct 181 ms 10196 KB Output is correct
36 Correct 197 ms 11456 KB Output is correct
37 Correct 210 ms 11192 KB Output is correct
38 Correct 184 ms 11044 KB Output is correct
39 Correct 200 ms 11192 KB Output is correct
40 Correct 169 ms 11260 KB Output is correct
41 Correct 102 ms 2956 KB Output is correct
42 Correct 164 ms 8580 KB Output is correct
43 Correct 224 ms 14716 KB Output is correct
44 Correct 96 ms 4632 KB Output is correct
45 Correct 161 ms 11156 KB Output is correct
46 Correct 223 ms 14876 KB Output is correct
47 Correct 206 ms 12236 KB Output is correct
48 Correct 220 ms 12332 KB Output is correct