Submission #732739

# Submission time Handle Problem Language Result Execution time Memory
732739 2023-04-29T08:46:45 Z minhcool Circle selection (APIO18_circle_selection) C++17
87 / 100
3000 ms 134952 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n, x[N], y[N], r[N];

int ans[N];

bool out[N];

unordered_map<int, int> mp;
vector<ii> vc[N];

bool ck(int i, int j){
//	cout << i << " " << j << "\n";
	int dist = ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
	int rd = (r[i] + r[j]) * (r[i] + r[j]);
	return (dist <= rd);
}

void process(){
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
	set<ii> rem;
	for(int i = 1; i <= n; i++) rem.insert({-r[i], i});
	bool chk = 1;
	for(int i = 1; i <= n; i++) chk &= (r[i] == 1);
	if(chk){
		for(int i = 1; i <= n; i++) cout << i << " ";
		cout << "\n";
		exit(0);
	}
	for(int i = 32; i >= 0; i--){// executing with radius (1LL << (i - 1)) to (1LL << i)
		int rad = (1LL << i);
		mp.clear();
		for(int j = 1; j <= n; j++) vc[j].clear();
		vector<int> diff;
		for(int j = 1; j <= n; j++) if(!out[j]) diff.pb(x[j] / rad);
		sort(diff.begin(), diff.end());
		diff.resize(unique(diff.begin(), diff.end()) - diff.begin());
		for(int j = 0; j < diff.size(); j++) mp[diff[j]] = j + 1;
		for(int j = 1; j <= n; j++){
			if(!out[j]){
				//cout << "OK " << rad << " " << j << " " << x[j]/rad << " " << y[j] << "\n";
				vc[mp[x[j]/rad]].pb({y[j], j});
			}
		}
		for(int j = 1; j <= n; j++) sort(vc[j].begin(), vc[j].end());
		while(!rem.empty() && -((*rem.begin()).fi) >= (1LL << (i - 1))){
			int ind = (*rem.begin()).se;
		//	cout << rad << " " << ind << "\n";
			assert(!out[ind]);
			out[ind] = 1;
			ans[ind] = ind;
			rem.erase({-r[ind], ind});
			for(int i2 = x[ind]/rad - 5; i2 <= x[ind]/rad + 5; i2++){
				if(mp.find(i2) == mp.end()) continue;
				int temp = mp[i2];
				int le = (y[ind]/rad) - 5, ri = (y[ind] / rad) + 5;
			//	cout << 
				le *= rad, ri *= rad;
			//	cout << le << " " << ri << "\n";
				vector<ii>::iterator it = lower_bound(vc[temp].begin(), vc[temp].end(), make_pair(le, -oo));
				for(; it != vc[temp].end(); it++){
					if((*it).fi > ri) break;
					if(out[(*it).se]) continue;
					if(ck(ind, (*it).se)){
						//cout << ind << " " << (*it).se << "\n";
						ans[(*it).se] = ind;
						rem.erase({-r[(*it).se], (*it).se});
						out[(*it).se] = 1;
					}
				}
			}
		}
	}
	for(int i = 1; i <= n; i++) if(!ans[i]) ans[i] = i;
	for(int i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}

Compilation message

circle_selection.cpp: In function 'void process()':
circle_selection.cpp:54:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < diff.size(); j++) mp[diff[j]] = j + 1;
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7396 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 5 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7512 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 5 ms 7596 KB Output is correct
19 Correct 10 ms 8292 KB Output is correct
20 Correct 11 ms 8276 KB Output is correct
21 Correct 10 ms 8276 KB Output is correct
22 Correct 22 ms 8832 KB Output is correct
23 Correct 21 ms 8572 KB Output is correct
24 Correct 29 ms 8992 KB Output is correct
25 Correct 26 ms 9100 KB Output is correct
26 Correct 23 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 570 ms 53712 KB Output is correct
2 Correct 644 ms 60960 KB Output is correct
3 Correct 577 ms 61384 KB Output is correct
4 Correct 521 ms 53756 KB Output is correct
5 Correct 1250 ms 85512 KB Output is correct
6 Correct 1764 ms 118132 KB Output is correct
7 Correct 1268 ms 92116 KB Output is correct
8 Correct 1353 ms 108288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 425 ms 35368 KB Output is correct
3 Correct 1629 ms 106144 KB Output is correct
4 Correct 1576 ms 106588 KB Output is correct
5 Correct 1447 ms 94856 KB Output is correct
6 Correct 655 ms 54568 KB Output is correct
7 Correct 363 ms 32404 KB Output is correct
8 Correct 62 ms 12908 KB Output is correct
9 Correct 1656 ms 107564 KB Output is correct
10 Correct 1419 ms 89500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1497 ms 105316 KB Output is correct
2 Correct 166 ms 42276 KB Output is correct
3 Correct 1095 ms 74416 KB Output is correct
4 Correct 2053 ms 118820 KB Output is correct
5 Correct 2263 ms 132204 KB Output is correct
6 Correct 1014 ms 75360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7396 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 5 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7512 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 5 ms 7596 KB Output is correct
19 Correct 10 ms 8292 KB Output is correct
20 Correct 11 ms 8276 KB Output is correct
21 Correct 10 ms 8276 KB Output is correct
22 Correct 22 ms 8832 KB Output is correct
23 Correct 21 ms 8572 KB Output is correct
24 Correct 29 ms 8992 KB Output is correct
25 Correct 26 ms 9100 KB Output is correct
26 Correct 23 ms 8916 KB Output is correct
27 Correct 17 ms 9000 KB Output is correct
28 Correct 19 ms 8968 KB Output is correct
29 Correct 18 ms 8956 KB Output is correct
30 Correct 48 ms 10048 KB Output is correct
31 Correct 45 ms 10736 KB Output is correct
32 Correct 40 ms 10540 KB Output is correct
33 Correct 166 ms 23376 KB Output is correct
34 Correct 172 ms 23320 KB Output is correct
35 Correct 180 ms 25952 KB Output is correct
36 Correct 492 ms 41508 KB Output is correct
37 Correct 505 ms 40184 KB Output is correct
38 Correct 497 ms 38128 KB Output is correct
39 Correct 664 ms 30844 KB Output is correct
40 Correct 676 ms 30932 KB Output is correct
41 Correct 681 ms 30920 KB Output is correct
42 Correct 525 ms 29320 KB Output is correct
43 Correct 574 ms 48472 KB Output is correct
44 Correct 591 ms 48456 KB Output is correct
45 Correct 579 ms 48468 KB Output is correct
46 Correct 583 ms 48448 KB Output is correct
47 Correct 558 ms 48524 KB Output is correct
48 Correct 591 ms 48460 KB Output is correct
49 Correct 591 ms 48324 KB Output is correct
50 Correct 593 ms 48448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 5 ms 7396 KB Output is correct
10 Correct 5 ms 7380 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7380 KB Output is correct
13 Correct 5 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7512 KB Output is correct
17 Correct 5 ms 7508 KB Output is correct
18 Correct 5 ms 7596 KB Output is correct
19 Correct 10 ms 8292 KB Output is correct
20 Correct 11 ms 8276 KB Output is correct
21 Correct 10 ms 8276 KB Output is correct
22 Correct 22 ms 8832 KB Output is correct
23 Correct 21 ms 8572 KB Output is correct
24 Correct 29 ms 8992 KB Output is correct
25 Correct 26 ms 9100 KB Output is correct
26 Correct 23 ms 8916 KB Output is correct
27 Correct 570 ms 53712 KB Output is correct
28 Correct 644 ms 60960 KB Output is correct
29 Correct 577 ms 61384 KB Output is correct
30 Correct 521 ms 53756 KB Output is correct
31 Correct 1250 ms 85512 KB Output is correct
32 Correct 1764 ms 118132 KB Output is correct
33 Correct 1268 ms 92116 KB Output is correct
34 Correct 1353 ms 108288 KB Output is correct
35 Correct 5 ms 7380 KB Output is correct
36 Correct 425 ms 35368 KB Output is correct
37 Correct 1629 ms 106144 KB Output is correct
38 Correct 1576 ms 106588 KB Output is correct
39 Correct 1447 ms 94856 KB Output is correct
40 Correct 655 ms 54568 KB Output is correct
41 Correct 363 ms 32404 KB Output is correct
42 Correct 62 ms 12908 KB Output is correct
43 Correct 1656 ms 107564 KB Output is correct
44 Correct 1419 ms 89500 KB Output is correct
45 Correct 1497 ms 105316 KB Output is correct
46 Correct 166 ms 42276 KB Output is correct
47 Correct 1095 ms 74416 KB Output is correct
48 Correct 2053 ms 118820 KB Output is correct
49 Correct 2263 ms 132204 KB Output is correct
50 Correct 1014 ms 75360 KB Output is correct
51 Correct 17 ms 9000 KB Output is correct
52 Correct 19 ms 8968 KB Output is correct
53 Correct 18 ms 8956 KB Output is correct
54 Correct 48 ms 10048 KB Output is correct
55 Correct 45 ms 10736 KB Output is correct
56 Correct 40 ms 10540 KB Output is correct
57 Correct 166 ms 23376 KB Output is correct
58 Correct 172 ms 23320 KB Output is correct
59 Correct 180 ms 25952 KB Output is correct
60 Correct 492 ms 41508 KB Output is correct
61 Correct 505 ms 40184 KB Output is correct
62 Correct 497 ms 38128 KB Output is correct
63 Correct 664 ms 30844 KB Output is correct
64 Correct 676 ms 30932 KB Output is correct
65 Correct 681 ms 30920 KB Output is correct
66 Correct 525 ms 29320 KB Output is correct
67 Correct 574 ms 48472 KB Output is correct
68 Correct 591 ms 48456 KB Output is correct
69 Correct 579 ms 48468 KB Output is correct
70 Correct 583 ms 48448 KB Output is correct
71 Correct 558 ms 48524 KB Output is correct
72 Correct 591 ms 48460 KB Output is correct
73 Correct 591 ms 48324 KB Output is correct
74 Correct 593 ms 48448 KB Output is correct
75 Correct 736 ms 60156 KB Output is correct
76 Correct 831 ms 62112 KB Output is correct
77 Correct 764 ms 55992 KB Output is correct
78 Correct 671 ms 56032 KB Output is correct
79 Correct 884 ms 62124 KB Output is correct
80 Correct 690 ms 56028 KB Output is correct
81 Correct 1781 ms 109040 KB Output is correct
82 Correct 1757 ms 101600 KB Output is correct
83 Correct 1786 ms 114444 KB Output is correct
84 Correct 1632 ms 107288 KB Output is correct
85 Correct 1732 ms 106600 KB Output is correct
86 Correct 1732 ms 105004 KB Output is correct
87 Correct 1618 ms 84620 KB Output is correct
88 Correct 2571 ms 84772 KB Output is correct
89 Correct 2722 ms 84760 KB Output is correct
90 Correct 2545 ms 84944 KB Output is correct
91 Correct 2558 ms 84300 KB Output is correct
92 Correct 2616 ms 84692 KB Output is correct
93 Correct 2664 ms 132128 KB Output is correct
94 Correct 1656 ms 54600 KB Output is correct
95 Correct 2870 ms 133540 KB Output is correct
96 Correct 2588 ms 130120 KB Output is correct
97 Correct 1897 ms 70196 KB Output is correct
98 Correct 1968 ms 111628 KB Output is correct
99 Correct 2949 ms 134952 KB Output is correct
100 Execution timed out 3070 ms 122664 KB Time limit exceeded
101 Halted 0 ms 0 KB -