답안 #598970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598970 2022-07-19T08:30:50 Z ignus Snowball (JOI21_ho_t2) C++14
100 / 100
261 ms 14844 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 212 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 356 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 312 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 3 ms 312 KB Output is correct
16 Correct 3 ms 360 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 356 KB Output is correct
5 Correct 3 ms 316 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 312 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 3 ms 312 KB Output is correct
16 Correct 3 ms 360 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 85 ms 3388 KB Output is correct
21 Correct 82 ms 3160 KB Output is correct
22 Correct 89 ms 2948 KB Output is correct
23 Correct 93 ms 2752 KB Output is correct
24 Correct 92 ms 3536 KB Output is correct
25 Correct 234 ms 11500 KB Output is correct
26 Correct 242 ms 11540 KB Output is correct
27 Correct 223 ms 11080 KB Output is correct
28 Correct 214 ms 11120 KB Output is correct
29 Correct 211 ms 10232 KB Output is correct
30 Correct 170 ms 9044 KB Output is correct
31 Correct 209 ms 8492 KB Output is correct
32 Correct 177 ms 8568 KB Output is correct
33 Correct 25 ms 1352 KB Output is correct
34 Correct 218 ms 10856 KB Output is correct
35 Correct 261 ms 10120 KB Output is correct
36 Correct 259 ms 11560 KB Output is correct
37 Correct 254 ms 11168 KB Output is correct
38 Correct 238 ms 11120 KB Output is correct
39 Correct 216 ms 11268 KB Output is correct
40 Correct 195 ms 11236 KB Output is correct
41 Correct 122 ms 2948 KB Output is correct
42 Correct 150 ms 8540 KB Output is correct
43 Correct 254 ms 14744 KB Output is correct
44 Correct 107 ms 4588 KB Output is correct
45 Correct 183 ms 11176 KB Output is correct
46 Correct 241 ms 14844 KB Output is correct
47 Correct 240 ms 12316 KB Output is correct
48 Correct 229 ms 12416 KB Output is correct