Submission #90998

# Submission time Handle Problem Language Result Execution time Memory
90998 2018-12-25T13:40:27 Z tincamatei Circle selection (APIO18_circle_selection) C++14
100 / 100
2697 ms 381252 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 300000;
int xc[1+MAX_N], yc[1+MAX_N], rc[1+MAX_N];
int rez[1+MAX_N];
int poz[1+MAX_N];
int poz2[1+MAX_N];

bool cmp(int a, int b) {
	return rc[a] > rc[b] || (rc[a] == rc[b] && a < b);
}

bool cmp2(int a, int b) {
	return xc[a] < xc[b] || (xc[a] == xc[b] && yc[a] < yc[b]);
}

bool cmp3(int a, int b) {
	return yc[a] < yc[b];
}

double dist(int a, int b) {
	return sqrt((long long)(xc[a] - xc[b]) * (xc[a] - xc[b]) +
	            (long long)(yc[a] - yc[b]) * (yc[a] - yc[b]));
}

vector<pair<int, vector<int> > > grid, aux;

void init(int n, int d) {
	sort(poz2, poz2 + n, cmp2);

	int lastx = -1;
	for(int i = 0; i < n; ++i) {
		int p = poz2[i];
		
		if(xc[p] / d == lastx)
			grid.back().second.push_back(p);
		else {
			lastx = xc[p] / d;
			grid.push_back(make_pair(lastx, vector<int>(1, p)));
		}
	}
	
	for(int i = 0; i < grid.size(); ++i)
		sort(grid[i].second.begin(), grid[i].second.end(), cmp3);
}

void rescale(int n, int d) {
	for(auto it: grid) {
		vector<int> st, dr;
		for(auto it2: it.second) {
			if(xc[it2] / d == it.first * 2)
				st.push_back(it2);
			else
				dr.push_back(it2);
		}

		if(st.size() > 0)
			aux.push_back(make_pair(it.first * 2, st));
		if(dr.size() > 0)
			aux.push_back(make_pair(it.first * 2 + 1, dr));
	}
	grid.clear();
	grid = aux;
	aux.clear();
}

int getStrip(int x) {
	int st = 0, dr = grid.size();
	while(dr - st > 1) {
		int mid = (st + dr) / 2;
		if(grid[mid].first <= x)
			st = mid;
		else
			dr = mid;
	}

	return st;
}

int getFirstE(int strip, int y) {
	int st = -1, dr = grid[strip].second.size();
	while(dr - st > 1) {
		int mid = (st + dr) / 2;
		if(yc[grid[strip].second[mid]] < y)
			st = mid;
		else
			dr = mid;
	}
	return dr;
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n;
	int mnx, mny;

	mnx = mny = 1000000000;
	
	fscanf(fin, "%d", &n);
	for(int i = 1; i <= n; ++i) {
		fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
		mnx = min(mnx, xc[i]);
		mny = min(mny, yc[i]);
		poz[i - 1] = poz2[i - 1] = i;
	}

	for(int i = 1; i <= n; ++i) {
		xc[i] -= mnx;
		yc[i] -= mny;
	}

	sort(poz, poz + n, cmp);

	int lastr = (1 << 30);
	init(n, lastr);

	for(int i = 0; i < n; ++i) {
		int p = poz[i];

		while(rc[p] * 2 <= lastr) {
			lastr /= 2;
			rescale(n, lastr);
		}
		
		if(rez[p] == 0) {
			int x2 = xc[p] / lastr, y2 = yc[p] / lastr;
			for(int strip = x2 - 2; strip <= x2 + 2; ++strip) {
				int pstrip = getStrip(strip);
				if(grid[pstrip].first == strip) {
					int j = getFirstE(pstrip, (y2 - 2) * lastr);
					while(j < grid[pstrip].second.size() &&
					      yc[grid[pstrip].second[j]] < (long long)(y2 + 3) * lastr) {
						int p2 = grid[pstrip].second[j];
						
						if(rez[p2] == 0 && dist(p, p2) <= rc[p] + rc[p2])
							rez[p2] = p;

						++j;
					}
				}
			}
		}
	}

	for(int i = 1; i <= n; ++i)
		fprintf(fout, "%d ", rez[i]);

#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}

Compilation message

circle_selection.cpp: In function 'void init(int, int)':
circle_selection.cpp:45:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < grid.size(); ++i)
                 ~~^~~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:140:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while(j < grid[pstrip].second.size() &&
            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:108:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d", &n);
  ~~~~~~^~~~~~~~~~~~~~~
circle_selection.cpp:110:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d%d", &xc[i], &yc[i], &rc[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 13 ms 548 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 3 ms 776 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 8 ms 1256 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 7 ms 1464 KB Output is correct
22 Correct 22 ms 2548 KB Output is correct
23 Correct 18 ms 2548 KB Output is correct
24 Correct 24 ms 2824 KB Output is correct
25 Correct 26 ms 2972 KB Output is correct
26 Correct 22 ms 3100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 545 ms 37724 KB Output is correct
2 Correct 956 ms 54472 KB Output is correct
3 Correct 739 ms 54472 KB Output is correct
4 Correct 547 ms 54472 KB Output is correct
5 Correct 558 ms 54472 KB Output is correct
6 Correct 1413 ms 57508 KB Output is correct
7 Correct 912 ms 57508 KB Output is correct
8 Correct 986 ms 57508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 57508 KB Output is correct
2 Correct 711 ms 57508 KB Output is correct
3 Correct 2317 ms 58072 KB Output is correct
4 Correct 2594 ms 64564 KB Output is correct
5 Correct 2173 ms 65308 KB Output is correct
6 Correct 868 ms 65308 KB Output is correct
7 Correct 470 ms 65308 KB Output is correct
8 Correct 76 ms 65308 KB Output is correct
9 Correct 2485 ms 66744 KB Output is correct
10 Correct 1727 ms 66744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 861 ms 66744 KB Output is correct
2 Correct 1938 ms 66744 KB Output is correct
3 Correct 359 ms 66744 KB Output is correct
4 Correct 1260 ms 67320 KB Output is correct
5 Correct 1166 ms 78604 KB Output is correct
6 Correct 335 ms 78604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 13 ms 548 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 3 ms 776 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 8 ms 1256 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 7 ms 1464 KB Output is correct
22 Correct 22 ms 2548 KB Output is correct
23 Correct 18 ms 2548 KB Output is correct
24 Correct 24 ms 2824 KB Output is correct
25 Correct 26 ms 2972 KB Output is correct
26 Correct 22 ms 3100 KB Output is correct
27 Correct 25 ms 78604 KB Output is correct
28 Correct 14 ms 78604 KB Output is correct
29 Correct 18 ms 78604 KB Output is correct
30 Correct 40 ms 78604 KB Output is correct
31 Correct 41 ms 78604 KB Output is correct
32 Correct 44 ms 78604 KB Output is correct
33 Correct 142 ms 78604 KB Output is correct
34 Correct 172 ms 78604 KB Output is correct
35 Correct 162 ms 78604 KB Output is correct
36 Correct 583 ms 78604 KB Output is correct
37 Correct 566 ms 78604 KB Output is correct
38 Correct 598 ms 78604 KB Output is correct
39 Correct 251 ms 78604 KB Output is correct
40 Correct 248 ms 78604 KB Output is correct
41 Correct 270 ms 78604 KB Output is correct
42 Correct 141 ms 78604 KB Output is correct
43 Correct 331 ms 78604 KB Output is correct
44 Correct 311 ms 78604 KB Output is correct
45 Correct 356 ms 78604 KB Output is correct
46 Correct 307 ms 78604 KB Output is correct
47 Correct 308 ms 78604 KB Output is correct
48 Correct 323 ms 78604 KB Output is correct
49 Correct 316 ms 78604 KB Output is correct
50 Correct 309 ms 78604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 13 ms 548 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Correct 2 ms 676 KB Output is correct
10 Correct 2 ms 676 KB Output is correct
11 Correct 2 ms 676 KB Output is correct
12 Correct 2 ms 676 KB Output is correct
13 Correct 2 ms 676 KB Output is correct
14 Correct 2 ms 676 KB Output is correct
15 Correct 2 ms 676 KB Output is correct
16 Correct 3 ms 776 KB Output is correct
17 Correct 3 ms 808 KB Output is correct
18 Correct 3 ms 808 KB Output is correct
19 Correct 8 ms 1256 KB Output is correct
20 Correct 6 ms 1280 KB Output is correct
21 Correct 7 ms 1464 KB Output is correct
22 Correct 22 ms 2548 KB Output is correct
23 Correct 18 ms 2548 KB Output is correct
24 Correct 24 ms 2824 KB Output is correct
25 Correct 26 ms 2972 KB Output is correct
26 Correct 22 ms 3100 KB Output is correct
27 Correct 545 ms 37724 KB Output is correct
28 Correct 956 ms 54472 KB Output is correct
29 Correct 739 ms 54472 KB Output is correct
30 Correct 547 ms 54472 KB Output is correct
31 Correct 558 ms 54472 KB Output is correct
32 Correct 1413 ms 57508 KB Output is correct
33 Correct 912 ms 57508 KB Output is correct
34 Correct 986 ms 57508 KB Output is correct
35 Correct 2 ms 57508 KB Output is correct
36 Correct 711 ms 57508 KB Output is correct
37 Correct 2317 ms 58072 KB Output is correct
38 Correct 2594 ms 64564 KB Output is correct
39 Correct 2173 ms 65308 KB Output is correct
40 Correct 868 ms 65308 KB Output is correct
41 Correct 470 ms 65308 KB Output is correct
42 Correct 76 ms 65308 KB Output is correct
43 Correct 2485 ms 66744 KB Output is correct
44 Correct 1727 ms 66744 KB Output is correct
45 Correct 861 ms 66744 KB Output is correct
46 Correct 1938 ms 66744 KB Output is correct
47 Correct 359 ms 66744 KB Output is correct
48 Correct 1260 ms 67320 KB Output is correct
49 Correct 1166 ms 78604 KB Output is correct
50 Correct 335 ms 78604 KB Output is correct
51 Correct 25 ms 78604 KB Output is correct
52 Correct 14 ms 78604 KB Output is correct
53 Correct 18 ms 78604 KB Output is correct
54 Correct 40 ms 78604 KB Output is correct
55 Correct 41 ms 78604 KB Output is correct
56 Correct 44 ms 78604 KB Output is correct
57 Correct 142 ms 78604 KB Output is correct
58 Correct 172 ms 78604 KB Output is correct
59 Correct 162 ms 78604 KB Output is correct
60 Correct 583 ms 78604 KB Output is correct
61 Correct 566 ms 78604 KB Output is correct
62 Correct 598 ms 78604 KB Output is correct
63 Correct 251 ms 78604 KB Output is correct
64 Correct 248 ms 78604 KB Output is correct
65 Correct 270 ms 78604 KB Output is correct
66 Correct 141 ms 78604 KB Output is correct
67 Correct 331 ms 78604 KB Output is correct
68 Correct 311 ms 78604 KB Output is correct
69 Correct 356 ms 78604 KB Output is correct
70 Correct 307 ms 78604 KB Output is correct
71 Correct 308 ms 78604 KB Output is correct
72 Correct 323 ms 78604 KB Output is correct
73 Correct 316 ms 78604 KB Output is correct
74 Correct 309 ms 78604 KB Output is correct
75 Correct 842 ms 94940 KB Output is correct
76 Correct 678 ms 94940 KB Output is correct
77 Correct 507 ms 94940 KB Output is correct
78 Correct 608 ms 103216 KB Output is correct
79 Correct 918 ms 129224 KB Output is correct
80 Correct 630 ms 129224 KB Output is correct
81 Correct 2388 ms 152124 KB Output is correct
82 Correct 2372 ms 160044 KB Output is correct
83 Correct 2156 ms 167916 KB Output is correct
84 Correct 2137 ms 183372 KB Output is correct
85 Correct 2295 ms 184412 KB Output is correct
86 Correct 2697 ms 192500 KB Output is correct
87 Correct 2061 ms 200212 KB Output is correct
88 Correct 966 ms 200212 KB Output is correct
89 Correct 1038 ms 200212 KB Output is correct
90 Correct 948 ms 200212 KB Output is correct
91 Correct 956 ms 200212 KB Output is correct
92 Correct 963 ms 200212 KB Output is correct
93 Correct 2351 ms 224144 KB Output is correct
94 Correct 705 ms 224144 KB Output is correct
95 Correct 1852 ms 238576 KB Output is correct
96 Correct 1917 ms 245600 KB Output is correct
97 Correct 1065 ms 245600 KB Output is correct
98 Correct 1468 ms 259188 KB Output is correct
99 Correct 2487 ms 266808 KB Output is correct
100 Correct 2095 ms 273708 KB Output is correct
101 Correct 1206 ms 279384 KB Output is correct
102 Correct 2081 ms 287808 KB Output is correct
103 Correct 913 ms 287808 KB Output is correct
104 Correct 2392 ms 301164 KB Output is correct
105 Correct 484 ms 301164 KB Output is correct
106 Correct 933 ms 301164 KB Output is correct
107 Correct 951 ms 307096 KB Output is correct
108 Correct 858 ms 314356 KB Output is correct
109 Correct 1066 ms 321352 KB Output is correct
110 Correct 890 ms 328260 KB Output is correct
111 Correct 1010 ms 335548 KB Output is correct
112 Correct 986 ms 342620 KB Output is correct
113 Correct 991 ms 349472 KB Output is correct
114 Correct 983 ms 357208 KB Output is correct
115 Correct 959 ms 365240 KB Output is correct
116 Correct 1087 ms 381252 KB Output is correct