답안 #381771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381771 2021-03-25T21:36:03 Z rainboy 원 고르기 (APIO18_circle_selection) C
100 / 100
1016 ms 21844 KB
/* https://oj.uz/submission/66132 (Benq) */
#include <stdio.h>
#include <string.h>

#define N	300000
#define X	1000000000
#define C	25

unsigned int Z = 12345;

int rand_() {
	return (Z *= 3) >> 1;
}

int xx[N], yy[N], rr[N];

int intersect(int i, int j) {
	return (long long) (xx[i] - xx[j]) * (xx[i] - xx[j]) + (long long) (yy[i] - yy[j]) * (yy[i] - yy[j]) <= (long long) (rr[i] + rr[j]) * (rr[i] + rr[j]);
}

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k) {
			int c = rr[ii[j]] != rr[i_] ? rr[i_] - rr[ii[j]] : ii[j] - i_;

			if (c == 0)
				j++;
			else if (c < 0) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		}
		sort(ii, l, i);
		l = k;
	}
}

int compare(int x1, int y1, int x2, int y2) {
	return x1 != x2 ? (x1 < x2 ? -1 : 1) : (y1 == y2 ? 0 : (y1 < y2 ? -1 : 1));
}

int ii_[N], xx_[N], yy_[N], n, lg;

int idx(int x, int y) {
	int lower = -1, upper = n;

	while (upper - lower > 1) {
		int i = (lower + upper) / 2, x_ = xx_[ii_[i]], y_ = yy_[ii_[i]];

		if (x_ < x || x_ == x && y_ <= y)
			lower = i;
		else
			upper = i;
	}
	return lower;
}

int main() {
	static int ii[N], tmp[N], pp[N];
	int h, h_, i, j, cnt;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
		xx[i] += X, yy[i] += X;
		ii[i] = ii_[i] = i;
	}
	sort(ii, 0, n);
	memset(pp, -1, n * sizeof *pp);
	for (lg = 30, h = 0; lg >= 0; lg--) {
		int x, y, dx;

		for (i = 0; i < n; i++)
			xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
		while (h < n && rr[ii[h]] >= 1 << lg) {
			i = ii[h], x = xx_[i], y = yy_[i];
			if (pp[i] == -1)
				for (dx = -2; dx <= 2; dx++) {
					h_ = idx(x + dx, y - 3) + 1;
					while (h_ < n && xx_[ii_[h_]] == x + dx && yy_[ii_[h_]] <= y + 2) {
						j = ii_[h_];
						if (pp[j] == -1 && intersect(i, j))
							pp[j] = i;
						h_++;
					}
				}
			h++;
		}
		for (i = 0; i < n; i = j) {
			x = xx_[ii_[i]];
			j = i + 1;
			while (j < n && xx_[ii_[j]] == x)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((xx[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					tmp[cnt++] = ii_[h_];
			memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
		}
		for (i = 0; i < n; i = j) {
			x = xx[ii_[i]] >> lg, y = yy_[ii_[i]];
			j = i + 1;
			while (j < n && (xx[ii_[j]] >> lg) == x && yy_[ii_[j]] == y)
				j++;
			cnt = 0;
			for (h_ = i; h_ < j; h_++)
				if ((yy[ii_[h_]] >> lg & 1) == 0)
					ii_[i++] = ii_[h_];
				else
					tmp[cnt++] = ii_[h_];
			memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
		}
	}
	for (i = 0; i < n; i++)
		printf("%d ", pp[i] + 1);
	printf("\n");
	return 0;
}

Compilation message

circle_selection.c: In function 'idx':
circle_selection.c:55:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   55 |   if (x_ < x || x_ == x && y_ <= y)
      |                 ~~~~~~~~^~~~~~~~~~
circle_selection.c: In function 'main':
circle_selection.c:79:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |    xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
      |                      ~~~^~~
circle_selection.c:79:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |    xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
      |                                                ~~~^~~
circle_selection.c:67:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   67 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
circle_selection.c:69:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   69 |   scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 8 ms 492 KB Output is correct
22 Correct 10 ms 492 KB Output is correct
23 Correct 11 ms 492 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 10 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 456 ms 12644 KB Output is correct
2 Correct 456 ms 12524 KB Output is correct
3 Correct 449 ms 12652 KB Output is correct
4 Correct 457 ms 12516 KB Output is correct
5 Correct 365 ms 12908 KB Output is correct
6 Correct 558 ms 12972 KB Output is correct
7 Correct 416 ms 12908 KB Output is correct
8 Correct 444 ms 12856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 280 ms 4272 KB Output is correct
3 Correct 1016 ms 12316 KB Output is correct
4 Correct 1010 ms 12268 KB Output is correct
5 Correct 878 ms 12012 KB Output is correct
6 Correct 368 ms 6508 KB Output is correct
7 Correct 178 ms 3564 KB Output is correct
8 Correct 31 ms 1004 KB Output is correct
9 Correct 965 ms 12268 KB Output is correct
10 Correct 830 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 897 ms 12396 KB Output is correct
2 Correct 776 ms 12840 KB Output is correct
3 Correct 599 ms 12096 KB Output is correct
4 Correct 795 ms 12396 KB Output is correct
5 Correct 811 ms 12652 KB Output is correct
6 Correct 562 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 8 ms 492 KB Output is correct
22 Correct 10 ms 492 KB Output is correct
23 Correct 11 ms 492 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 10 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
27 Correct 16 ms 748 KB Output is correct
28 Correct 15 ms 748 KB Output is correct
29 Correct 19 ms 748 KB Output is correct
30 Correct 22 ms 748 KB Output is correct
31 Correct 21 ms 748 KB Output is correct
32 Correct 21 ms 748 KB Output is correct
33 Correct 159 ms 4460 KB Output is correct
34 Correct 164 ms 4460 KB Output is correct
35 Correct 178 ms 4460 KB Output is correct
36 Correct 259 ms 4416 KB Output is correct
37 Correct 257 ms 4460 KB Output is correct
38 Correct 259 ms 4460 KB Output is correct
39 Correct 165 ms 4460 KB Output is correct
40 Correct 164 ms 4460 KB Output is correct
41 Correct 166 ms 4460 KB Output is correct
42 Correct 127 ms 4460 KB Output is correct
43 Correct 214 ms 4204 KB Output is correct
44 Correct 217 ms 4204 KB Output is correct
45 Correct 214 ms 4204 KB Output is correct
46 Correct 212 ms 4204 KB Output is correct
47 Correct 217 ms 4204 KB Output is correct
48 Correct 216 ms 4204 KB Output is correct
49 Correct 214 ms 4204 KB Output is correct
50 Correct 217 ms 4204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 8 ms 492 KB Output is correct
20 Correct 7 ms 492 KB Output is correct
21 Correct 8 ms 492 KB Output is correct
22 Correct 10 ms 492 KB Output is correct
23 Correct 11 ms 492 KB Output is correct
24 Correct 11 ms 492 KB Output is correct
25 Correct 10 ms 492 KB Output is correct
26 Correct 11 ms 492 KB Output is correct
27 Correct 456 ms 12644 KB Output is correct
28 Correct 456 ms 12524 KB Output is correct
29 Correct 449 ms 12652 KB Output is correct
30 Correct 457 ms 12516 KB Output is correct
31 Correct 365 ms 12908 KB Output is correct
32 Correct 558 ms 12972 KB Output is correct
33 Correct 416 ms 12908 KB Output is correct
34 Correct 444 ms 12856 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 280 ms 4272 KB Output is correct
37 Correct 1016 ms 12316 KB Output is correct
38 Correct 1010 ms 12268 KB Output is correct
39 Correct 878 ms 12012 KB Output is correct
40 Correct 368 ms 6508 KB Output is correct
41 Correct 178 ms 3564 KB Output is correct
42 Correct 31 ms 1004 KB Output is correct
43 Correct 965 ms 12268 KB Output is correct
44 Correct 830 ms 12160 KB Output is correct
45 Correct 897 ms 12396 KB Output is correct
46 Correct 776 ms 12840 KB Output is correct
47 Correct 599 ms 12096 KB Output is correct
48 Correct 795 ms 12396 KB Output is correct
49 Correct 811 ms 12652 KB Output is correct
50 Correct 562 ms 12268 KB Output is correct
51 Correct 16 ms 748 KB Output is correct
52 Correct 15 ms 748 KB Output is correct
53 Correct 19 ms 748 KB Output is correct
54 Correct 22 ms 748 KB Output is correct
55 Correct 21 ms 748 KB Output is correct
56 Correct 21 ms 748 KB Output is correct
57 Correct 159 ms 4460 KB Output is correct
58 Correct 164 ms 4460 KB Output is correct
59 Correct 178 ms 4460 KB Output is correct
60 Correct 259 ms 4416 KB Output is correct
61 Correct 257 ms 4460 KB Output is correct
62 Correct 259 ms 4460 KB Output is correct
63 Correct 165 ms 4460 KB Output is correct
64 Correct 164 ms 4460 KB Output is correct
65 Correct 166 ms 4460 KB Output is correct
66 Correct 127 ms 4460 KB Output is correct
67 Correct 214 ms 4204 KB Output is correct
68 Correct 217 ms 4204 KB Output is correct
69 Correct 214 ms 4204 KB Output is correct
70 Correct 212 ms 4204 KB Output is correct
71 Correct 217 ms 4204 KB Output is correct
72 Correct 216 ms 4204 KB Output is correct
73 Correct 214 ms 4204 KB Output is correct
74 Correct 217 ms 4204 KB Output is correct
75 Correct 550 ms 12780 KB Output is correct
76 Correct 508 ms 21612 KB Output is correct
77 Correct 530 ms 21580 KB Output is correct
78 Correct 531 ms 21672 KB Output is correct
79 Correct 640 ms 21484 KB Output is correct
80 Correct 533 ms 21844 KB Output is correct
81 Correct 976 ms 20672 KB Output is correct
82 Correct 945 ms 20204 KB Output is correct
83 Correct 980 ms 20204 KB Output is correct
84 Correct 956 ms 20716 KB Output is correct
85 Correct 942 ms 20588 KB Output is correct
86 Correct 949 ms 20352 KB Output is correct
87 Correct 978 ms 20972 KB Output is correct
88 Correct 591 ms 16108 KB Output is correct
89 Correct 608 ms 16364 KB Output is correct
90 Correct 602 ms 16228 KB Output is correct
91 Correct 588 ms 16108 KB Output is correct
92 Correct 588 ms 16108 KB Output is correct
93 Correct 740 ms 19948 KB Output is correct
94 Correct 718 ms 20460 KB Output is correct
95 Correct 746 ms 19820 KB Output is correct
96 Correct 737 ms 19948 KB Output is correct
97 Correct 925 ms 19820 KB Output is correct
98 Correct 569 ms 20204 KB Output is correct
99 Correct 760 ms 19752 KB Output is correct
100 Correct 750 ms 19180 KB Output is correct
101 Correct 675 ms 20332 KB Output is correct
102 Correct 749 ms 19820 KB Output is correct
103 Correct 874 ms 19948 KB Output is correct
104 Correct 781 ms 19264 KB Output is correct
105 Correct 474 ms 17628 KB Output is correct
106 Correct 703 ms 20204 KB Output is correct
107 Correct 703 ms 20460 KB Output is correct
108 Correct 715 ms 20332 KB Output is correct
109 Correct 705 ms 20288 KB Output is correct
110 Correct 708 ms 20332 KB Output is correct
111 Correct 699 ms 20408 KB Output is correct
112 Correct 744 ms 20204 KB Output is correct
113 Correct 702 ms 20204 KB Output is correct
114 Correct 732 ms 20332 KB Output is correct
115 Correct 701 ms 20332 KB Output is correct
116 Correct 711 ms 20024 KB Output is correct