Submission #794621

# Submission time Handle Problem Language Result Execution time Memory
794621 2023-07-26T16:56:10 Z dlalswp25 Circle selection (APIO18_circle_selection) C++17
7 / 100
3000 ms 410628 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef tuple<int, int, int> piii;

const int INF = 2020202020;

int N;
int X[303030];
int Y[303030];
int R[303030];
int C[303030][4];
int ans[303030];
int Q[8][2][3] = {
	{{1, 3, 0}, {1, 0, 0}},
	{{0, 3, 1}, {1, 1, 0}},
	{{0, 2, 1}, {0, 1, 0}},
	{{1, 2, 0}, {1, 0, 1}},
	{{1, 3, 0}, {0, 1, 1}},
	{{0, 3, 1}, {0, 0, 1}},
	{{0, 2, 1}, {1, 0, 1}},
	{{1, 2, 0}, {0, 1, 0}}
};

struct BIT {
	struct Node {
		set<piii> S;

		void add(piii x) {
			auto it = S.insert(x).first;
			if (it != S.begin() && std::get<1>(*prev(it)) <= std::get<1>(*it)) {
				S.erase(it); return;
			}
			while (next(it) != S.end() && std::get<1>(*next(it)) >= std::get<1>(*it)) {
				S.erase(next(it));
			}
		}

		pii get(int y) {
			auto it = S.lower_bound(piii(y + 1, -INF, 0));
			if (it == S.begin()) return {INF, 0};
			int _, z, i; tie(_, z, i) = *prev(it);
			return {z, i};
		}
	};

	int n;
	vector<Node> T;

	BIT(int _n) : n(_n), T(_n + 1) {}

	void upd(int x, int y, int z, int i) {
		piii t(y, z, i);
		for (int i = x; i <= n; i += i&-i) T[i].add(t);
	}

	int query(int x, int y) {
		pii ret = {INF, 0};
		for (int i = x; i; i -= i&-i) ret = min(ret, T[i].get(y));
		return ret.second;
	}
};

bool intersect(int i, int j) {
	long long dx = X[i] - X[j], dy = Y[i] - Y[j], r = R[i] + R[j];
	return dx * dx + dy * dy <= r * r;
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d%d%d", &X[i], &Y[i], &R[i]);
		C[i][0] = X[i];
		C[i][1] = Y[i];
		C[i][2] = X[i] + Y[i];
		C[i][3] = Y[i] - X[i];
	}
	for (int i = 0; i < 4; i++) {
		vector<int> v;
		for (int j = 1; j <= N; j++) v.push_back(C[j][i]);
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		for (int j = 1; j <= N; j++) {
			C[j][i] = lower_bound(v.begin(), v.end(), C[j][i]) - v.begin() + 1;
		}
	}

	BIT seg[8] {
		{N}, {N}, {N}, {N}, {N}, {N}, {N}, {N}
	};

	vector<int> V(N);
	iota(V.begin(), V.end(), 1);
	sort(V.begin(), V.end(), [&](int a, int b) {
		if (R[a] == R[b]) return a < b;
		return R[a] > R[b];
	});

	for (int i : V) {
		ans[i] = i;
		int x[8][3];
		for (int j = 0; j < 8; j++) {
			for (int k = 0; k < 3; k++) {
				x[j][k] = C[i][Q[j][0][k]];
				if (Q[j][1][k]) x[j][k] = N - x[j][k] + 1;
			}
		}
		for (int j = 0; j < 8; j++) {
			int t = seg[j].query(x[j][0], x[j][1]);
			if (!t || !intersect(i, t)) continue;
			if (pii(R[t], -t) > pii(R[ans[i]], -ans[i])) ans[i] = t;
		}
		if (ans[i] == i) {
			for (int j = 0; j < 8; j++) {
				seg[j].upd(x[j][0], x[j][1], x[j][2], i);
			}
		}
	}
	for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
	return 0;
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:120:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  120 |  for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
      |  ^~~
circle_selection.cpp:120:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  120 |  for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
      |                                                      ^~~~
circle_selection.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
circle_selection.cpp:73:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   scanf("%d%d%d", &X[i], &Y[i], &R[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 276 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 444 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 7 ms 2596 KB Output is correct
20 Correct 7 ms 2588 KB Output is correct
21 Correct 7 ms 2604 KB Output is correct
22 Correct 73 ms 12792 KB Output is correct
23 Correct 58 ms 12688 KB Output is correct
24 Correct 63 ms 12748 KB Output is correct
25 Correct 62 ms 12720 KB Output is correct
26 Correct 61 ms 12772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 709 ms 132468 KB Output is correct
2 Correct 669 ms 132404 KB Output is correct
3 Correct 646 ms 132076 KB Output is correct
4 Correct 641 ms 132428 KB Output is correct
5 Correct 996 ms 146196 KB Output is correct
6 Execution timed out 3068 ms 410628 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 3078 ms 207008 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 297280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 276 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 444 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 7 ms 2596 KB Output is correct
20 Correct 7 ms 2588 KB Output is correct
21 Correct 7 ms 2604 KB Output is correct
22 Correct 73 ms 12792 KB Output is correct
23 Correct 58 ms 12688 KB Output is correct
24 Correct 63 ms 12748 KB Output is correct
25 Correct 62 ms 12720 KB Output is correct
26 Correct 61 ms 12772 KB Output is correct
27 Correct 14 ms 4820 KB Output is correct
28 Correct 20 ms 4768 KB Output is correct
29 Correct 14 ms 4804 KB Output is correct
30 Correct 212 ms 26384 KB Output is correct
31 Correct 231 ms 26364 KB Output is correct
32 Correct 179 ms 26420 KB Output is correct
33 Correct 257 ms 45052 KB Output is correct
34 Correct 283 ms 45068 KB Output is correct
35 Correct 279 ms 45256 KB Output is correct
36 Execution timed out 3082 ms 199788 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 276 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 444 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 2 ms 724 KB Output is correct
19 Correct 7 ms 2596 KB Output is correct
20 Correct 7 ms 2588 KB Output is correct
21 Correct 7 ms 2604 KB Output is correct
22 Correct 73 ms 12792 KB Output is correct
23 Correct 58 ms 12688 KB Output is correct
24 Correct 63 ms 12748 KB Output is correct
25 Correct 62 ms 12720 KB Output is correct
26 Correct 61 ms 12772 KB Output is correct
27 Correct 709 ms 132468 KB Output is correct
28 Correct 669 ms 132404 KB Output is correct
29 Correct 646 ms 132076 KB Output is correct
30 Correct 641 ms 132428 KB Output is correct
31 Correct 996 ms 146196 KB Output is correct
32 Execution timed out 3068 ms 410628 KB Time limit exceeded
33 Halted 0 ms 0 KB -