Submission #984739

# Submission time Handle Problem Language Result Execution time Memory
984739 2024-05-17T04:03:35 Z qwerasdfzxcl Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 189464 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")

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);

			if (_+1 == CHK) break;
			
			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");
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 58200 KB Output is correct
2 Correct 12 ms 57948 KB Output is correct
3 Correct 12 ms 57948 KB Output is correct
4 Correct 12 ms 57948 KB Output is correct
5 Correct 12 ms 57948 KB Output is correct
6 Correct 12 ms 58096 KB Output is correct
7 Correct 12 ms 57944 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 57944 KB Output is correct
11 Correct 11 ms 58052 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 58108 KB Output is correct
15 Correct 12 ms 57948 KB Output is correct
16 Correct 12 ms 57956 KB Output is correct
17 Correct 13 ms 57948 KB Output is correct
18 Correct 13 ms 57940 KB Output is correct
19 Correct 18 ms 60552 KB Output is correct
20 Correct 16 ms 60248 KB Output is correct
21 Correct 17 ms 60252 KB Output is correct
22 Correct 18 ms 60760 KB Output is correct
23 Correct 22 ms 61276 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60272 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 446 ms 70752 KB Output is correct
2 Correct 455 ms 70052 KB Output is correct
3 Correct 450 ms 69308 KB Output is correct
4 Correct 443 ms 71360 KB Output is correct
5 Correct 406 ms 71720 KB Output is correct
6 Correct 478 ms 81668 KB Output is correct
7 Correct 456 ms 73828 KB Output is correct
8 Correct 467 ms 75864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 58100 KB Output is correct
2 Correct 310 ms 85620 KB Output is correct
3 Correct 1122 ms 136964 KB Output is correct
4 Correct 1094 ms 135360 KB Output is correct
5 Correct 1299 ms 132652 KB Output is correct
6 Correct 492 ms 87324 KB Output is correct
7 Correct 177 ms 70644 KB Output is correct
8 Correct 31 ms 61408 KB Output is correct
9 Correct 1175 ms 138492 KB Output is correct
10 Correct 1517 ms 127996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 895 ms 127504 KB Output is correct
2 Correct 415 ms 90940 KB Output is correct
3 Correct 838 ms 76992 KB Output is correct
4 Correct 477 ms 94400 KB Output is correct
5 Correct 433 ms 92608 KB Output is correct
6 Correct 744 ms 71036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 58200 KB Output is correct
2 Correct 12 ms 57948 KB Output is correct
3 Correct 12 ms 57948 KB Output is correct
4 Correct 12 ms 57948 KB Output is correct
5 Correct 12 ms 57948 KB Output is correct
6 Correct 12 ms 58096 KB Output is correct
7 Correct 12 ms 57944 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 57944 KB Output is correct
11 Correct 11 ms 58052 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 58108 KB Output is correct
15 Correct 12 ms 57948 KB Output is correct
16 Correct 12 ms 57956 KB Output is correct
17 Correct 13 ms 57948 KB Output is correct
18 Correct 13 ms 57940 KB Output is correct
19 Correct 18 ms 60552 KB Output is correct
20 Correct 16 ms 60248 KB Output is correct
21 Correct 17 ms 60252 KB Output is correct
22 Correct 18 ms 60760 KB Output is correct
23 Correct 22 ms 61276 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60272 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 26 ms 60248 KB Output is correct
28 Correct 22 ms 60252 KB Output is correct
29 Correct 22 ms 60352 KB Output is correct
30 Correct 28 ms 62032 KB Output is correct
31 Correct 24 ms 61132 KB Output is correct
32 Correct 23 ms 61272 KB Output is correct
33 Correct 125 ms 63448 KB Output is correct
34 Correct 130 ms 63692 KB Output is correct
35 Correct 139 ms 63608 KB Output is correct
36 Correct 191 ms 76236 KB Output is correct
37 Correct 199 ms 76620 KB Output is correct
38 Correct 223 ms 78796 KB Output is correct
39 Correct 165 ms 66444 KB Output is correct
40 Correct 164 ms 66508 KB Output is correct
41 Correct 163 ms 66508 KB Output is correct
42 Correct 172 ms 66508 KB Output is correct
43 Correct 133 ms 69832 KB Output is correct
44 Correct 153 ms 69788 KB Output is correct
45 Correct 151 ms 70092 KB Output is correct
46 Correct 138 ms 70272 KB Output is correct
47 Correct 130 ms 69324 KB Output is correct
48 Correct 134 ms 70272 KB Output is correct
49 Correct 131 ms 69068 KB Output is correct
50 Correct 132 ms 69832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 58200 KB Output is correct
2 Correct 12 ms 57948 KB Output is correct
3 Correct 12 ms 57948 KB Output is correct
4 Correct 12 ms 57948 KB Output is correct
5 Correct 12 ms 57948 KB Output is correct
6 Correct 12 ms 58096 KB Output is correct
7 Correct 12 ms 57944 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 57944 KB Output is correct
11 Correct 11 ms 58052 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 58108 KB Output is correct
15 Correct 12 ms 57948 KB Output is correct
16 Correct 12 ms 57956 KB Output is correct
17 Correct 13 ms 57948 KB Output is correct
18 Correct 13 ms 57940 KB Output is correct
19 Correct 18 ms 60552 KB Output is correct
20 Correct 16 ms 60248 KB Output is correct
21 Correct 17 ms 60252 KB Output is correct
22 Correct 18 ms 60760 KB Output is correct
23 Correct 22 ms 61276 KB Output is correct
24 Correct 17 ms 60508 KB Output is correct
25 Correct 17 ms 60272 KB Output is correct
26 Correct 17 ms 60508 KB Output is correct
27 Correct 446 ms 70752 KB Output is correct
28 Correct 455 ms 70052 KB Output is correct
29 Correct 450 ms 69308 KB Output is correct
30 Correct 443 ms 71360 KB Output is correct
31 Correct 406 ms 71720 KB Output is correct
32 Correct 478 ms 81668 KB Output is correct
33 Correct 456 ms 73828 KB Output is correct
34 Correct 467 ms 75864 KB Output is correct
35 Correct 12 ms 58100 KB Output is correct
36 Correct 310 ms 85620 KB Output is correct
37 Correct 1122 ms 136964 KB Output is correct
38 Correct 1094 ms 135360 KB Output is correct
39 Correct 1299 ms 132652 KB Output is correct
40 Correct 492 ms 87324 KB Output is correct
41 Correct 177 ms 70644 KB Output is correct
42 Correct 31 ms 61408 KB Output is correct
43 Correct 1175 ms 138492 KB Output is correct
44 Correct 1517 ms 127996 KB Output is correct
45 Correct 895 ms 127504 KB Output is correct
46 Correct 415 ms 90940 KB Output is correct
47 Correct 838 ms 76992 KB Output is correct
48 Correct 477 ms 94400 KB Output is correct
49 Correct 433 ms 92608 KB Output is correct
50 Correct 744 ms 71036 KB Output is correct
51 Correct 26 ms 60248 KB Output is correct
52 Correct 22 ms 60252 KB Output is correct
53 Correct 22 ms 60352 KB Output is correct
54 Correct 28 ms 62032 KB Output is correct
55 Correct 24 ms 61132 KB Output is correct
56 Correct 23 ms 61272 KB Output is correct
57 Correct 125 ms 63448 KB Output is correct
58 Correct 130 ms 63692 KB Output is correct
59 Correct 139 ms 63608 KB Output is correct
60 Correct 191 ms 76236 KB Output is correct
61 Correct 199 ms 76620 KB Output is correct
62 Correct 223 ms 78796 KB Output is correct
63 Correct 165 ms 66444 KB Output is correct
64 Correct 164 ms 66508 KB Output is correct
65 Correct 163 ms 66508 KB Output is correct
66 Correct 172 ms 66508 KB Output is correct
67 Correct 133 ms 69832 KB Output is correct
68 Correct 153 ms 69788 KB Output is correct
69 Correct 151 ms 70092 KB Output is correct
70 Correct 138 ms 70272 KB Output is correct
71 Correct 130 ms 69324 KB Output is correct
72 Correct 134 ms 70272 KB Output is correct
73 Correct 131 ms 69068 KB Output is correct
74 Correct 132 ms 69832 KB Output is correct
75 Correct 447 ms 70080 KB Output is correct
76 Correct 452 ms 70612 KB Output is correct
77 Correct 390 ms 69496 KB Output is correct
78 Correct 422 ms 70336 KB Output is correct
79 Correct 567 ms 71500 KB Output is correct
80 Correct 429 ms 70180 KB Output is correct
81 Correct 1044 ms 130380 KB Output is correct
82 Correct 878 ms 121984 KB Output is correct
83 Correct 897 ms 122304 KB Output is correct
84 Correct 1303 ms 145600 KB Output is correct
85 Correct 987 ms 128192 KB Output is correct
86 Correct 849 ms 118976 KB Output is correct
87 Correct 2503 ms 189464 KB Output is correct
88 Correct 561 ms 78600 KB Output is correct
89 Correct 595 ms 78528 KB Output is correct
90 Correct 564 ms 79796 KB Output is correct
91 Correct 540 ms 79040 KB Output is correct
92 Correct 557 ms 78272 KB Output is correct
93 Correct 433 ms 91580 KB Output is correct
94 Correct 2873 ms 148124 KB Output is correct
95 Correct 430 ms 91424 KB Output is correct
96 Correct 445 ms 92172 KB Output is correct
97 Correct 1941 ms 123908 KB Output is correct
98 Correct 494 ms 83648 KB Output is correct
99 Correct 437 ms 92640 KB Output is correct
100 Correct 416 ms 91364 KB Output is correct
101 Correct 640 ms 94976 KB Output is correct
102 Correct 438 ms 90188 KB Output is correct
103 Execution timed out 3062 ms 143584 KB Time limit exceeded
104 Halted 0 ms 0 KB -