답안 #984737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
984737 2024-05-17T03:58:19 Z qwerasdfzxcl 원 고르기 (APIO18_circle_selection) C++17
87 / 100
3000 ms 189228 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr int INF = 1e9 + 100, CHK = 2;

struct Circle{
	int x, y, r, i, xl, xr;
	Circle(){}

	bool operator < (const Circle &C) const{
		if (r==C.r) return i < C.i;
		return r > C.r;
	}
}C[300300];
int ans[300300];

int ok(int i, int j){
	ll d = (ll)(C[i].x-C[j].x) * (C[i].x-C[j].x) + (ll)(C[i].y-C[j].y) * (C[i].y-C[j].y);
	ll r = (ll)(C[i].r + C[j].r) * (C[i].r + C[j].r);
	return d <= r;
}

struct Seg{

	int sz;
	map<int, int> tree[1201200];

	map<int, int>::iterator iter0[30], iter[30];
	int T[30], buf[30], pt, py = INF;

	void init(int n){
		sz = n;
	}

	void update(int l, int r, int y, int i){
		r++;
		for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
			if (l&1){
				tree[l][y] = i;
				l++;
			}
			if (r&1){
				--r;
				tree[r][y] = i;
			}
		}
	}

	int queryU(int x, int y, int i){
		pt = 0;
		for (int node=x+sz;node>0;node>>=1){
			if (y!=py || T[pt] != node) iter0[pt] = tree[node].lower_bound(y);
			iter[pt] = iter0[pt];
			T[pt] = node;
			buf[pt] = (iter[pt]==tree[T[pt]].end())?INF:iter[pt]->first;
			pt++;
		}

		py = y;

		int ret = i;

		for (int _=0;_<CHK;_++){
			int idx = min_element(buf, buf+pt) - buf;
			if (buf[idx]==INF) break;
			if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
			
			iter[idx]++;
			buf[idx] = (iter[idx]==tree[T[idx]].end())?INF:iter[idx]->first;
		}

		return ret;

	}

	int queryD(int i){
		for (int i=0;i<pt;i++){
			iter[i] = iter0[i];
			buf[i] = (iter[i]==tree[T[i]].begin())?(-INF):prev(iter[i])->first;
		}

		int ret = i;

		for (int _=0;_<CHK;_++){
			int idx = max_element(buf, buf+pt) - buf;
			if (buf[idx]==-INF) break;
			
			iter[idx]--;
			if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
			
			buf[idx] = (iter[idx]==tree[T[idx]].begin())?(-INF):prev(iter[idx])->first;
		}

		return ret;
	}
}tree;

int calc(int x, int i){
	int ret = i;
	ret = min(ret, tree.queryU(x, C[i].y, i));
	ret = min(ret, tree.queryD(i));

	return ret;
}

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

	int n;
	cin >> n;

	vector<int> X;
	for (int i=1;i<=n;i++){
		cin >> C[i].x >> C[i].y >> C[i].r;
		X.push_back(C[i].x - C[i].r);
		X.push_back(C[i].x + C[i].r);

		C[i].i = i;
	}

	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	for (int i=1;i<=n;i++){
		C[i].xl = lower_bound(X.begin(), X.end(), C[i].x - C[i].r) - X.begin();
		C[i].xr = lower_bound(X.begin(), X.end(), C[i].x + C[i].r) - X.begin();
	}

	sort(C+1, C+n+1);
	tree.init(X.size());

	for (int i=1;i<=n;i++){
		ans[C[i].i] = min(calc(C[i].xl, i), calc(C[i].xr, i));
		if (ans[C[i].i]==i) tree.update(C[i].xl, C[i].xr, C[i].y, i);

		ans[C[i].i] = C[ans[C[i].i]].i;
	}

	for (int i=1;i<=n;i++) printf("%d ", ans[i]);
	printf("\n");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 57944 KB Output is correct
2 Correct 11 ms 57948 KB Output is correct
3 Correct 14 ms 57944 KB Output is correct
4 Correct 11 ms 57948 KB Output is correct
5 Correct 13 ms 57948 KB Output is correct
6 Correct 12 ms 57948 KB Output is correct
7 Correct 12 ms 57948 KB Output is correct
8 Correct 12 ms 57948 KB Output is correct
9 Correct 12 ms 57948 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 12 ms 58016 KB Output is correct
12 Correct 12 ms 57948 KB Output is correct
13 Correct 12 ms 57948 KB Output is correct
14 Correct 12 ms 57948 KB Output is correct
15 Correct 14 ms 57944 KB Output is correct
16 Correct 13 ms 58108 KB Output is correct
17 Correct 13 ms 58104 KB Output is correct
18 Correct 13 ms 57948 KB Output is correct
19 Correct 17 ms 60064 KB Output is correct
20 Correct 17 ms 60248 KB Output is correct
21 Correct 20 ms 60508 KB Output is correct
22 Correct 19 ms 60600 KB Output is correct
23 Correct 22 ms 61268 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60460 KB Output is correct
26 Correct 17 ms 60436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 435 ms 70872 KB Output is correct
2 Correct 484 ms 69568 KB Output is correct
3 Correct 444 ms 69824 KB Output is correct
4 Correct 428 ms 69568 KB Output is correct
5 Correct 403 ms 71612 KB Output is correct
6 Correct 489 ms 80612 KB Output is correct
7 Correct 447 ms 73392 KB Output is correct
8 Correct 453 ms 75452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 57948 KB Output is correct
2 Correct 318 ms 85804 KB Output is correct
3 Correct 1116 ms 136140 KB Output is correct
4 Correct 1108 ms 134584 KB Output is correct
5 Correct 1329 ms 133576 KB Output is correct
6 Correct 526 ms 87128 KB Output is correct
7 Correct 177 ms 70604 KB Output is correct
8 Correct 32 ms 61344 KB Output is correct
9 Correct 1220 ms 138516 KB Output is correct
10 Correct 1624 ms 127832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 920 ms 127620 KB Output is correct
2 Correct 415 ms 91908 KB Output is correct
3 Correct 910 ms 77764 KB Output is correct
4 Correct 459 ms 94828 KB Output is correct
5 Correct 425 ms 92092 KB Output is correct
6 Correct 757 ms 71568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 57944 KB Output is correct
2 Correct 11 ms 57948 KB Output is correct
3 Correct 14 ms 57944 KB Output is correct
4 Correct 11 ms 57948 KB Output is correct
5 Correct 13 ms 57948 KB Output is correct
6 Correct 12 ms 57948 KB Output is correct
7 Correct 12 ms 57948 KB Output is correct
8 Correct 12 ms 57948 KB Output is correct
9 Correct 12 ms 57948 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 12 ms 58016 KB Output is correct
12 Correct 12 ms 57948 KB Output is correct
13 Correct 12 ms 57948 KB Output is correct
14 Correct 12 ms 57948 KB Output is correct
15 Correct 14 ms 57944 KB Output is correct
16 Correct 13 ms 58108 KB Output is correct
17 Correct 13 ms 58104 KB Output is correct
18 Correct 13 ms 57948 KB Output is correct
19 Correct 17 ms 60064 KB Output is correct
20 Correct 17 ms 60248 KB Output is correct
21 Correct 20 ms 60508 KB Output is correct
22 Correct 19 ms 60600 KB Output is correct
23 Correct 22 ms 61268 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60460 KB Output is correct
26 Correct 17 ms 60436 KB Output is correct
27 Correct 22 ms 60252 KB Output is correct
28 Correct 22 ms 60260 KB Output is correct
29 Correct 21 ms 60356 KB Output is correct
30 Correct 29 ms 61932 KB Output is correct
31 Correct 23 ms 61276 KB Output is correct
32 Correct 24 ms 61272 KB Output is correct
33 Correct 129 ms 63692 KB Output is correct
34 Correct 149 ms 63616 KB Output is correct
35 Correct 135 ms 63692 KB Output is correct
36 Correct 196 ms 76160 KB Output is correct
37 Correct 208 ms 76748 KB Output is correct
38 Correct 233 ms 78864 KB Output is correct
39 Correct 172 ms 66500 KB Output is correct
40 Correct 168 ms 66536 KB Output is correct
41 Correct 170 ms 66508 KB Output is correct
42 Correct 177 ms 66508 KB Output is correct
43 Correct 138 ms 70052 KB Output is correct
44 Correct 130 ms 69756 KB Output is correct
45 Correct 129 ms 70160 KB Output is correct
46 Correct 131 ms 70032 KB Output is correct
47 Correct 134 ms 69328 KB Output is correct
48 Correct 130 ms 70348 KB Output is correct
49 Correct 125 ms 68992 KB Output is correct
50 Correct 136 ms 69844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 57944 KB Output is correct
2 Correct 11 ms 57948 KB Output is correct
3 Correct 14 ms 57944 KB Output is correct
4 Correct 11 ms 57948 KB Output is correct
5 Correct 13 ms 57948 KB Output is correct
6 Correct 12 ms 57948 KB Output is correct
7 Correct 12 ms 57948 KB Output is correct
8 Correct 12 ms 57948 KB Output is correct
9 Correct 12 ms 57948 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 12 ms 58016 KB Output is correct
12 Correct 12 ms 57948 KB Output is correct
13 Correct 12 ms 57948 KB Output is correct
14 Correct 12 ms 57948 KB Output is correct
15 Correct 14 ms 57944 KB Output is correct
16 Correct 13 ms 58108 KB Output is correct
17 Correct 13 ms 58104 KB Output is correct
18 Correct 13 ms 57948 KB Output is correct
19 Correct 17 ms 60064 KB Output is correct
20 Correct 17 ms 60248 KB Output is correct
21 Correct 20 ms 60508 KB Output is correct
22 Correct 19 ms 60600 KB Output is correct
23 Correct 22 ms 61268 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60460 KB Output is correct
26 Correct 17 ms 60436 KB Output is correct
27 Correct 435 ms 70872 KB Output is correct
28 Correct 484 ms 69568 KB Output is correct
29 Correct 444 ms 69824 KB Output is correct
30 Correct 428 ms 69568 KB Output is correct
31 Correct 403 ms 71612 KB Output is correct
32 Correct 489 ms 80612 KB Output is correct
33 Correct 447 ms 73392 KB Output is correct
34 Correct 453 ms 75452 KB Output is correct
35 Correct 11 ms 57948 KB Output is correct
36 Correct 318 ms 85804 KB Output is correct
37 Correct 1116 ms 136140 KB Output is correct
38 Correct 1108 ms 134584 KB Output is correct
39 Correct 1329 ms 133576 KB Output is correct
40 Correct 526 ms 87128 KB Output is correct
41 Correct 177 ms 70604 KB Output is correct
42 Correct 32 ms 61344 KB Output is correct
43 Correct 1220 ms 138516 KB Output is correct
44 Correct 1624 ms 127832 KB Output is correct
45 Correct 920 ms 127620 KB Output is correct
46 Correct 415 ms 91908 KB Output is correct
47 Correct 910 ms 77764 KB Output is correct
48 Correct 459 ms 94828 KB Output is correct
49 Correct 425 ms 92092 KB Output is correct
50 Correct 757 ms 71568 KB Output is correct
51 Correct 22 ms 60252 KB Output is correct
52 Correct 22 ms 60260 KB Output is correct
53 Correct 21 ms 60356 KB Output is correct
54 Correct 29 ms 61932 KB Output is correct
55 Correct 23 ms 61276 KB Output is correct
56 Correct 24 ms 61272 KB Output is correct
57 Correct 129 ms 63692 KB Output is correct
58 Correct 149 ms 63616 KB Output is correct
59 Correct 135 ms 63692 KB Output is correct
60 Correct 196 ms 76160 KB Output is correct
61 Correct 208 ms 76748 KB Output is correct
62 Correct 233 ms 78864 KB Output is correct
63 Correct 172 ms 66500 KB Output is correct
64 Correct 168 ms 66536 KB Output is correct
65 Correct 170 ms 66508 KB Output is correct
66 Correct 177 ms 66508 KB Output is correct
67 Correct 138 ms 70052 KB Output is correct
68 Correct 130 ms 69756 KB Output is correct
69 Correct 129 ms 70160 KB Output is correct
70 Correct 131 ms 70032 KB Output is correct
71 Correct 134 ms 69328 KB Output is correct
72 Correct 130 ms 70348 KB Output is correct
73 Correct 125 ms 68992 KB Output is correct
74 Correct 136 ms 69844 KB Output is correct
75 Correct 461 ms 70076 KB Output is correct
76 Correct 441 ms 70844 KB Output is correct
77 Correct 394 ms 69784 KB Output is correct
78 Correct 427 ms 70852 KB Output is correct
79 Correct 595 ms 69968 KB Output is correct
80 Correct 430 ms 69312 KB Output is correct
81 Correct 1049 ms 131368 KB Output is correct
82 Correct 896 ms 121696 KB Output is correct
83 Correct 894 ms 122676 KB Output is correct
84 Correct 1420 ms 146772 KB Output is correct
85 Correct 993 ms 128332 KB Output is correct
86 Correct 879 ms 119204 KB Output is correct
87 Correct 2637 ms 189228 KB Output is correct
88 Correct 651 ms 78648 KB Output is correct
89 Correct 573 ms 79812 KB Output is correct
90 Correct 593 ms 79528 KB Output is correct
91 Correct 669 ms 78180 KB Output is correct
92 Correct 668 ms 78756 KB Output is correct
93 Correct 422 ms 91072 KB Output is correct
94 Correct 2984 ms 146760 KB Output is correct
95 Correct 424 ms 97468 KB Output is correct
96 Correct 466 ms 98240 KB Output is correct
97 Correct 2090 ms 130056 KB Output is correct
98 Correct 497 ms 90788 KB Output is correct
99 Correct 434 ms 97900 KB Output is correct
100 Correct 416 ms 97636 KB Output is correct
101 Correct 675 ms 101256 KB Output is correct
102 Correct 438 ms 98476 KB Output is correct
103 Execution timed out 3009 ms 146168 KB Time limit exceeded
104 Halted 0 ms 0 KB -