Submission #372808

# Submission time Handle Problem Language Result Execution time Memory
372808 2021-03-01T20:13:50 Z luciocf Circle selection (APIO18_circle_selection) C++14
0 / 100
630 ms 25616 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;

struct Circle
{
	int x, y, r, ind;

	bool operator<(const pair<int, int> &o) const
	{
		return y < o.second;
	}
} circle[maxn];

vector<vector<Circle>> V;

int R;

int ans[maxn];
bool mark[maxn];

bool comp1(Circle a, Circle b)
{
	if (a.x < b.x) return a.y < b.y;
	return a.x < b.y;
}

bool comp2(Circle a, Circle b)
{
	if (a.r == b.r) return a.ind < b.r;
	return a.r > b.r;
}

bool intersect(Circle a, Circle b)
{
	int dx = a.x-b.x, dy = a.y-b.y;
	int dr = a.r+b.r;

	return 1ll*dx*dx + 1ll*dy*dy <= 1ll*dr*dr;
}

void doit(int pos, int c)
{
	int x = circle[c].x, y = circle[c].y;

	int l_y = max(0, y - (y%R) - 2*R), r_y = y - (y%R) + 2*R;

	auto it = lower_bound(V[pos].begin(), V[pos].end(), make_pair(V[pos][0].x, l_y));
	for (; it != V[pos].end() && it->y <= r_y; it++)
	{
		if (intersect(circle[c], *it))
		{
			ans[it->ind] = circle[c].ind;
			mark[it->ind] = 1;
		}
	}
}

int main(void)
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d %d", &circle[i].x, &circle[i].y, &circle[i].r);
		circle[i].ind = i;
	}

	R = circle[1].r;

	sort(circle+1, circle+n+1, comp1);

	for (int i = 1; i <= n; i++)
	{
		if (i == 1 || circle[i].x > circle[i-1].x)
			V.push_back(vector<Circle>());

		V.back().push_back(circle[i]);
	}

	sort(circle+1, circle+n+1, comp2);

	for (int i = 1; i <= n; i++)
	{
		if (mark[circle[i].ind]) continue;
		int x = circle[i].x, y = circle[i].y;

		int l_x = max(0, x - (x%R) - 2*R), r_x = x - (x%R) + 2*R;

		int p_l, p_r;

		int ini = 0, fim = (int)V.size()-1;

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (V[mid][0].x >= l_x) p_l = mid, fim = mid-1;
			else ini = mid+1;
		}

		ini = 0, fim = (int)V.size()-1;

		while (ini <= fim)
		{
			int mid = (ini+fim)>>1;

			if (V[mid][0].x <= r_x) p_r = mid, ini = mid+1;
			else fim = mid-1;
		}

		for (int j = p_l; j <= p_r; j++)
			doit(j, i);
	}

	for (int i = 1; i <= n; i++)
		printf("%d ", ans[i]);
	printf("\n");
}

Compilation message

circle_selection.cpp: In function 'void doit(int, int)':
circle_selection.cpp:46:6: warning: unused variable 'x' [-Wunused-variable]
   46 |  int x = circle[c].x, y = circle[c].y;
      |      ^
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:89:24: warning: unused variable 'y' [-Wunused-variable]
   89 |   int x = circle[i].x, y = circle[i].y;
      |                        ^
circle_selection.cpp:64:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   68 |   scanf("%d %d %d", &circle[i].x, &circle[i].y, &circle[i].r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:93:12: warning: 'p_r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |   int p_l, p_r;
      |            ^~~
circle_selection.cpp:115:3: warning: 'p_l' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |   for (int j = p_l; j <= p_r; j++)
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 412 ms 23964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 630 ms 25616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -