답안 #95382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
95382 2019-01-31T07:43:34 Z pranjalssh 원 고르기 (APIO18_circle_selection) C++14
37 / 100
3000 ms 244096 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 52 ms 56696 KB Output is correct
2 Correct 50 ms 56828 KB Output is correct
3 Correct 44 ms 56668 KB Output is correct
4 Correct 45 ms 56696 KB Output is correct
5 Correct 45 ms 56696 KB Output is correct
6 Correct 46 ms 56700 KB Output is correct
7 Correct 53 ms 56820 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 46 ms 56700 KB Output is correct
11 Correct 48 ms 56696 KB Output is correct
12 Correct 51 ms 56824 KB Output is correct
13 Correct 52 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56696 KB Output is correct
16 Correct 54 ms 57316 KB Output is correct
17 Correct 55 ms 57208 KB Output is correct
18 Correct 56 ms 57336 KB Output is correct
19 Correct 83 ms 60152 KB Output is correct
20 Correct 81 ms 60024 KB Output is correct
21 Correct 79 ms 60060 KB Output is correct
22 Correct 79 ms 59896 KB Output is correct
23 Correct 82 ms 59924 KB Output is correct
24 Correct 78 ms 59896 KB Output is correct
25 Correct 79 ms 59932 KB Output is correct
26 Correct 69 ms 59896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3042 ms 240140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 56696 KB Output is correct
2 Correct 2086 ms 142828 KB Output is correct
3 Execution timed out 3049 ms 201888 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3061 ms 244096 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 56696 KB Output is correct
2 Correct 50 ms 56828 KB Output is correct
3 Correct 44 ms 56668 KB Output is correct
4 Correct 45 ms 56696 KB Output is correct
5 Correct 45 ms 56696 KB Output is correct
6 Correct 46 ms 56700 KB Output is correct
7 Correct 53 ms 56820 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 46 ms 56700 KB Output is correct
11 Correct 48 ms 56696 KB Output is correct
12 Correct 51 ms 56824 KB Output is correct
13 Correct 52 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56696 KB Output is correct
16 Correct 54 ms 57316 KB Output is correct
17 Correct 55 ms 57208 KB Output is correct
18 Correct 56 ms 57336 KB Output is correct
19 Correct 83 ms 60152 KB Output is correct
20 Correct 81 ms 60024 KB Output is correct
21 Correct 79 ms 60060 KB Output is correct
22 Correct 79 ms 59896 KB Output is correct
23 Correct 82 ms 59924 KB Output is correct
24 Correct 78 ms 59896 KB Output is correct
25 Correct 79 ms 59932 KB Output is correct
26 Correct 69 ms 59896 KB Output is correct
27 Correct 108 ms 63948 KB Output is correct
28 Correct 134 ms 63896 KB Output is correct
29 Correct 135 ms 63972 KB Output is correct
30 Correct 139 ms 63728 KB Output is correct
31 Correct 126 ms 63828 KB Output is correct
32 Correct 133 ms 63736 KB Output is correct
33 Correct 1873 ms 143800 KB Output is correct
34 Correct 1888 ms 143748 KB Output is correct
35 Correct 1763 ms 143636 KB Output is correct
36 Correct 2113 ms 142704 KB Output is correct
37 Correct 2090 ms 142888 KB Output is correct
38 Correct 1606 ms 142716 KB Output is correct
39 Correct 1774 ms 109220 KB Output is correct
40 Correct 2605 ms 110316 KB Output is correct
41 Correct 2437 ms 110436 KB Output is correct
42 Correct 1588 ms 112524 KB Output is correct
43 Correct 1596 ms 145524 KB Output is correct
44 Correct 1669 ms 145504 KB Output is correct
45 Correct 1200 ms 145424 KB Output is correct
46 Correct 1002 ms 145336 KB Output is correct
47 Correct 1110 ms 145328 KB Output is correct
48 Correct 1018 ms 145520 KB Output is correct
49 Correct 1521 ms 145372 KB Output is correct
50 Correct 1123 ms 145396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 56696 KB Output is correct
2 Correct 50 ms 56828 KB Output is correct
3 Correct 44 ms 56668 KB Output is correct
4 Correct 45 ms 56696 KB Output is correct
5 Correct 45 ms 56696 KB Output is correct
6 Correct 46 ms 56700 KB Output is correct
7 Correct 53 ms 56820 KB Output is correct
8 Correct 45 ms 56696 KB Output is correct
9 Correct 52 ms 56696 KB Output is correct
10 Correct 46 ms 56700 KB Output is correct
11 Correct 48 ms 56696 KB Output is correct
12 Correct 51 ms 56824 KB Output is correct
13 Correct 52 ms 56696 KB Output is correct
14 Correct 52 ms 56696 KB Output is correct
15 Correct 54 ms 56696 KB Output is correct
16 Correct 54 ms 57316 KB Output is correct
17 Correct 55 ms 57208 KB Output is correct
18 Correct 56 ms 57336 KB Output is correct
19 Correct 83 ms 60152 KB Output is correct
20 Correct 81 ms 60024 KB Output is correct
21 Correct 79 ms 60060 KB Output is correct
22 Correct 79 ms 59896 KB Output is correct
23 Correct 82 ms 59924 KB Output is correct
24 Correct 78 ms 59896 KB Output is correct
25 Correct 79 ms 59932 KB Output is correct
26 Correct 69 ms 59896 KB Output is correct
27 Execution timed out 3042 ms 240140 KB Time limit exceeded
28 Halted 0 ms 0 KB -