답안 #95381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95381 2019-01-31T07:00:27 Z pranjalssh 원 고르기 (APIO18_circle_selection) C++14
7 / 100
3000 ms 250080 KB
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define cerr cout
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


const int N = 3e5 + 10;
vi x, y, r;
set<ii> T[4 * N + 10];
vi cmp;
vi par;
void ins(int no, int l, int r, int id) {
	T[no].emplace(y[id], id);
	if (l == r) return;
	int mid = (l + r) >> 1;
	if (x[id] <= cmp[mid]) ins(2 * no, l, mid, id);
	else ins(2 * no + 1, mid + 1, r, id);
}
vector<ii> rem;
inline bool intersect(int i, int j) {
	return (x[i] - x[j]) * 1LL * (x[i] - x[j]) + (y[i] - y[j]) * 1LL * (y[i] - y[j]) <= (r[i] + r[j]) * 1LL * (r[i] + r[j]);
}
void get(int no, int l, int r, int id) {
	int u = max(x[id] - 2LL *::r[id], (ll) - inf);
	int v = min(x[id] + 2LL *::r[id], (ll)inf);

	if (cmp[l] >= u and cmp[r] <= v) {
		u = max(y[id] - 2LL *::r[id], (ll) - inf);
		v = min(y[id] + 2LL *::r[id], (ll)inf);
		for (auto it = T[no].lower_bound(ii(u, -1)); it != T[no].end() and it->F <= v; it++) {
			int tid = it->S;
			if (par[tid] != -1) rem.emplace_back(y[tid], tid);
			else if (intersect(tid, id)) {
				par[tid] = id;
				rem.emplace_back(y[tid], tid);
			}
		}
		for (auto it : rem) {
			T[no].erase(it);
		}
		rem.clear();
		return;
	}

	if (cmp[r] < u or cmp[l] > v) return;
	int mid = (l + r) >> 1;
	get(2 * no, l, mid, id);
	get(2 * no + 1, mid + 1, r, id);

}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n; cin >> n;
	x.resize(n), y.resize(n), r.resize(n);
	par = vi(n, -1);

	FOR (i, 0, n - 1) {
		cin >> x[i] >> y[i] >> r[i];
		cmp.emplace_back(x[i]);
	}
	sort(all(cmp)); cmp.erase(unique(all(cmp)), cmp.end());

	vi id(n); iota(all(id), 0);
	sort(all(id), [&](int x, int y) {
		if (r[x] == r[y]) return x < y;
		return r[x] > r[y];
	});

	FOR (i, 0, n - 1) ins(1, 0, sz(cmp) - 1, i);

	for (int i : id) if (par[i] == -1) {
			get(1, 0, sz(cmp) - 1, i);
		}

	FOR (i, 0, n - 1) cout << par[i] + 1 << " ";



	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 56696 KB Output is correct
2 Correct 53 ms 56696 KB Output is correct
3 Correct 51 ms 56696 KB Output is correct
4 Correct 53 ms 56696 KB Output is correct
5 Correct 52 ms 56696 KB Output is correct
6 Correct 52 ms 56696 KB Output is correct
7 Correct 53 ms 56680 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 52 ms 56824 KB Output is correct
11 Correct 52 ms 56696 KB Output is correct
12 Correct 51 ms 56696 KB Output is correct
13 Correct 53 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56824 KB Output is correct
16 Correct 54 ms 57256 KB Output is correct
17 Correct 55 ms 57204 KB Output is correct
18 Correct 46 ms 57288 KB Output is correct
19 Correct 76 ms 60408 KB Output is correct
20 Correct 78 ms 60280 KB Output is correct
21 Correct 69 ms 60152 KB Output is correct
22 Correct 68 ms 60132 KB Output is correct
23 Correct 71 ms 60156 KB Output is correct
24 Correct 69 ms 60156 KB Output is correct
25 Correct 124 ms 60152 KB Output is correct
26 Correct 67 ms 60156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3045 ms 250080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 56668 KB Output is correct
2 Correct 2205 ms 145780 KB Output is correct
3 Execution timed out 3070 ms 228288 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3057 ms 215428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 56696 KB Output is correct
2 Correct 53 ms 56696 KB Output is correct
3 Correct 51 ms 56696 KB Output is correct
4 Correct 53 ms 56696 KB Output is correct
5 Correct 52 ms 56696 KB Output is correct
6 Correct 52 ms 56696 KB Output is correct
7 Correct 53 ms 56680 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 52 ms 56824 KB Output is correct
11 Correct 52 ms 56696 KB Output is correct
12 Correct 51 ms 56696 KB Output is correct
13 Correct 53 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56824 KB Output is correct
16 Correct 54 ms 57256 KB Output is correct
17 Correct 55 ms 57204 KB Output is correct
18 Correct 46 ms 57288 KB Output is correct
19 Correct 76 ms 60408 KB Output is correct
20 Correct 78 ms 60280 KB Output is correct
21 Correct 69 ms 60152 KB Output is correct
22 Correct 68 ms 60132 KB Output is correct
23 Correct 71 ms 60156 KB Output is correct
24 Correct 69 ms 60156 KB Output is correct
25 Correct 124 ms 60152 KB Output is correct
26 Correct 67 ms 60156 KB Output is correct
27 Correct 130 ms 64220 KB Output is correct
28 Correct 121 ms 64324 KB Output is correct
29 Correct 125 ms 64248 KB Output is correct
30 Correct 123 ms 63976 KB Output is correct
31 Correct 146 ms 63992 KB Output is correct
32 Correct 113 ms 64016 KB Output is correct
33 Correct 1842 ms 146736 KB Output is correct
34 Correct 2039 ms 146768 KB Output is correct
35 Correct 1942 ms 146672 KB Output is correct
36 Correct 1995 ms 145448 KB Output is correct
37 Correct 2016 ms 145440 KB Output is correct
38 Correct 2193 ms 145692 KB Output is correct
39 Execution timed out 3025 ms 110452 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 56696 KB Output is correct
2 Correct 53 ms 56696 KB Output is correct
3 Correct 51 ms 56696 KB Output is correct
4 Correct 53 ms 56696 KB Output is correct
5 Correct 52 ms 56696 KB Output is correct
6 Correct 52 ms 56696 KB Output is correct
7 Correct 53 ms 56680 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 52 ms 56824 KB Output is correct
11 Correct 52 ms 56696 KB Output is correct
12 Correct 51 ms 56696 KB Output is correct
13 Correct 53 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56824 KB Output is correct
16 Correct 54 ms 57256 KB Output is correct
17 Correct 55 ms 57204 KB Output is correct
18 Correct 46 ms 57288 KB Output is correct
19 Correct 76 ms 60408 KB Output is correct
20 Correct 78 ms 60280 KB Output is correct
21 Correct 69 ms 60152 KB Output is correct
22 Correct 68 ms 60132 KB Output is correct
23 Correct 71 ms 60156 KB Output is correct
24 Correct 69 ms 60156 KB Output is correct
25 Correct 124 ms 60152 KB Output is correct
26 Correct 67 ms 60156 KB Output is correct
27 Execution timed out 3045 ms 250080 KB Time limit exceeded
28 Halted 0 ms 0 KB -