Submission #875999

# Submission time Handle Problem Language Result Execution time Memory
875999 2023-11-21T03:58:47 Z marvinthang Circle selection (APIO18_circle_selection) C++17
100 / 100
882 ms 70796 KB
/*************************************
*    author: marvinthang             *
*    created: 21.11.2023 10:16:16    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i-- > 0; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

const int INF = 1e9;

struct Circle {
	int x, y, r, idx;
	Circle(int x, int y, int r, int idx): x(x), y(y), r(r), idx(idx) {}
	bool operator < (const Circle &ot) { return pair {r, ot.idx} > pair {ot.r, idx}; }
};

void process(void) {
	int n; cin >> n;
	vector <Circle> circles;
	int min_x = INF, min_y = INF, max_x = 0;
	REP(i, n) {
		int x, y, r; cin >> x >> y >> r;
		circles.emplace_back(x, y, r, i);
		min_x = min(min_x, x);
		min_y = min(min_y, y);
		max_x = max(max_x, x);
	}
	vector <vector <pair <int, int>>> List(1);
	REP(i, n) {
		circles[i].x -= min_x;
		circles[i].y -= min_y;
	}
	sort(ALL(circles));
	REP(i, n) List[0].emplace_back(circles[i].y, i);
	sort(ALL(List[0]));
	int lg = __lg(max_x - min_x) + 1;
	vector <int> res(n, -1);
	auto sqr = [&] (int x) {
		return 1LL * x * x;
	};
	auto intersection = [&] (int i, int j) {
		return sqr(circles[i].x - circles[j].x) + sqr(circles[i].y - circles[j].y) <= sqr(circles[i].r + circles[j].r);
	};
	REP(i, n) if (res[circles[i].idx] < 0) {
		while (lg && circles[i].r <= MASK(lg - 1)) {
			--lg;
			vector <vector <pair <int, int>>> new_list;
			for (auto List: List) {
				vector <vector <pair <int, int>>> cur(2);
				for (auto v: List) if (res[circles[v.se].idx] < 0) cur[(circles[v.se].x >> lg) & 1].push_back(v);
				REP(i, 2) if (!cur[i].empty()) new_list.push_back(cur[i]);
			}
			List = move(new_list);
		}
		auto cmp = [&] (const vector <pair <int, int>> &a, const int &x) { 
			return (circles[a[0].se].x >> lg) < x; 
		};
		for (auto it = lower_bound(ALL(List), (circles[i].x >> lg) - 2, cmp); it != List.end() && cmp(*it, (circles[i].x >> lg) + 3); ++it) {
			for (auto p = lower_bound(ALL(*it), circles[i].y - 2LL * circles[i].r, [&] (const pair <int, int> &a, const long long &x) { return a.fi < x; }); p != it->end() && p->fi <= circles[i].y + 2LL * circles[i].r; ++p) 
				if (res[circles[p->se].idx] < 0 && intersection(p->se, i)) res[circles[p->se].idx] = circles[i].idx;
		}

	}
	REP(i, n) cout << res[i] + 1 << ' ';
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
	file("circle_selection");
	// int t; cin >> t; while (t--)
	process();
	// cerr << "Time elapsed: " << TIME << " s.\n";
	return (0^0);
}

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:105:2: note: in expansion of macro 'file'
  105 |  file("circle_selection");
      |  ^~~~
circle_selection.cpp:30:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:105:2: note: in expansion of macro 'file'
  105 |  file("circle_selection");
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 5 ms 1112 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 6 ms 1116 KB Output is correct
25 Correct 8 ms 1372 KB Output is correct
26 Correct 6 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 121 ms 19128 KB Output is correct
2 Correct 121 ms 19428 KB Output is correct
3 Correct 120 ms 20008 KB Output is correct
4 Correct 118 ms 19016 KB Output is correct
5 Correct 143 ms 19384 KB Output is correct
6 Correct 267 ms 23044 KB Output is correct
7 Correct 157 ms 20916 KB Output is correct
8 Correct 176 ms 20508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 98 ms 6092 KB Output is correct
3 Correct 336 ms 31636 KB Output is correct
4 Correct 328 ms 30744 KB Output is correct
5 Correct 277 ms 26900 KB Output is correct
6 Correct 130 ms 15808 KB Output is correct
7 Correct 67 ms 7364 KB Output is correct
8 Correct 16 ms 2264 KB Output is correct
9 Correct 314 ms 27108 KB Output is correct
10 Correct 295 ms 30220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 21516 KB Output is correct
2 Correct 751 ms 70796 KB Output is correct
3 Correct 161 ms 29672 KB Output is correct
4 Correct 478 ms 53928 KB Output is correct
5 Correct 556 ms 59188 KB Output is correct
6 Correct 156 ms 30168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 5 ms 1112 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 6 ms 1116 KB Output is correct
25 Correct 8 ms 1372 KB Output is correct
26 Correct 6 ms 1116 KB Output is correct
27 Correct 5 ms 1112 KB Output is correct
28 Correct 4 ms 1116 KB Output is correct
29 Correct 5 ms 1112 KB Output is correct
30 Correct 9 ms 1676 KB Output is correct
31 Correct 11 ms 1724 KB Output is correct
32 Correct 10 ms 1680 KB Output is correct
33 Correct 46 ms 7348 KB Output is correct
34 Correct 47 ms 7480 KB Output is correct
35 Correct 48 ms 8908 KB Output is correct
36 Correct 113 ms 10544 KB Output is correct
37 Correct 113 ms 10596 KB Output is correct
38 Correct 108 ms 9384 KB Output is correct
39 Correct 131 ms 8772 KB Output is correct
40 Correct 123 ms 8784 KB Output is correct
41 Correct 133 ms 9000 KB Output is correct
42 Correct 53 ms 7888 KB Output is correct
43 Correct 153 ms 19264 KB Output is correct
44 Correct 145 ms 19960 KB Output is correct
45 Correct 142 ms 19688 KB Output is correct
46 Correct 141 ms 19144 KB Output is correct
47 Correct 145 ms 19240 KB Output is correct
48 Correct 140 ms 18140 KB Output is correct
49 Correct 149 ms 19208 KB Output is correct
50 Correct 145 ms 19528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 728 KB Output is correct
20 Correct 2 ms 852 KB Output is correct
21 Correct 2 ms 724 KB Output is correct
22 Correct 5 ms 1112 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 6 ms 1116 KB Output is correct
25 Correct 8 ms 1372 KB Output is correct
26 Correct 6 ms 1116 KB Output is correct
27 Correct 121 ms 19128 KB Output is correct
28 Correct 121 ms 19428 KB Output is correct
29 Correct 120 ms 20008 KB Output is correct
30 Correct 118 ms 19016 KB Output is correct
31 Correct 143 ms 19384 KB Output is correct
32 Correct 267 ms 23044 KB Output is correct
33 Correct 157 ms 20916 KB Output is correct
34 Correct 176 ms 20508 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 98 ms 6092 KB Output is correct
37 Correct 336 ms 31636 KB Output is correct
38 Correct 328 ms 30744 KB Output is correct
39 Correct 277 ms 26900 KB Output is correct
40 Correct 130 ms 15808 KB Output is correct
41 Correct 67 ms 7364 KB Output is correct
42 Correct 16 ms 2264 KB Output is correct
43 Correct 314 ms 27108 KB Output is correct
44 Correct 295 ms 30220 KB Output is correct
45 Correct 309 ms 21516 KB Output is correct
46 Correct 751 ms 70796 KB Output is correct
47 Correct 161 ms 29672 KB Output is correct
48 Correct 478 ms 53928 KB Output is correct
49 Correct 556 ms 59188 KB Output is correct
50 Correct 156 ms 30168 KB Output is correct
51 Correct 5 ms 1112 KB Output is correct
52 Correct 4 ms 1116 KB Output is correct
53 Correct 5 ms 1112 KB Output is correct
54 Correct 9 ms 1676 KB Output is correct
55 Correct 11 ms 1724 KB Output is correct
56 Correct 10 ms 1680 KB Output is correct
57 Correct 46 ms 7348 KB Output is correct
58 Correct 47 ms 7480 KB Output is correct
59 Correct 48 ms 8908 KB Output is correct
60 Correct 113 ms 10544 KB Output is correct
61 Correct 113 ms 10596 KB Output is correct
62 Correct 108 ms 9384 KB Output is correct
63 Correct 131 ms 8772 KB Output is correct
64 Correct 123 ms 8784 KB Output is correct
65 Correct 133 ms 9000 KB Output is correct
66 Correct 53 ms 7888 KB Output is correct
67 Correct 153 ms 19264 KB Output is correct
68 Correct 145 ms 19960 KB Output is correct
69 Correct 142 ms 19688 KB Output is correct
70 Correct 141 ms 19144 KB Output is correct
71 Correct 145 ms 19240 KB Output is correct
72 Correct 140 ms 18140 KB Output is correct
73 Correct 149 ms 19208 KB Output is correct
74 Correct 145 ms 19528 KB Output is correct
75 Correct 146 ms 26808 KB Output is correct
76 Correct 149 ms 30644 KB Output is correct
77 Correct 144 ms 24304 KB Output is correct
78 Correct 141 ms 25864 KB Output is correct
79 Correct 176 ms 29932 KB Output is correct
80 Correct 141 ms 25036 KB Output is correct
81 Correct 362 ms 28508 KB Output is correct
82 Correct 339 ms 31040 KB Output is correct
83 Correct 341 ms 29144 KB Output is correct
84 Correct 342 ms 32184 KB Output is correct
85 Correct 358 ms 29012 KB Output is correct
86 Correct 368 ms 32096 KB Output is correct
87 Correct 329 ms 30980 KB Output is correct
88 Correct 478 ms 25820 KB Output is correct
89 Correct 457 ms 26652 KB Output is correct
90 Correct 479 ms 29240 KB Output is correct
91 Correct 501 ms 25396 KB Output is correct
92 Correct 482 ms 27620 KB Output is correct
93 Correct 718 ms 58332 KB Output is correct
94 Correct 339 ms 29576 KB Output is correct
95 Correct 709 ms 60144 KB Output is correct
96 Correct 607 ms 53532 KB Output is correct
97 Correct 381 ms 27788 KB Output is correct
98 Correct 304 ms 33264 KB Output is correct
99 Correct 733 ms 63092 KB Output is correct
100 Correct 882 ms 63572 KB Output is correct
101 Correct 352 ms 27424 KB Output is correct
102 Correct 610 ms 61944 KB Output is correct
103 Correct 270 ms 27064 KB Output is correct
104 Correct 730 ms 61756 KB Output is correct
105 Correct 171 ms 26432 KB Output is correct
106 Correct 415 ms 42932 KB Output is correct
107 Correct 432 ms 40952 KB Output is correct
108 Correct 407 ms 43700 KB Output is correct
109 Correct 447 ms 42472 KB Output is correct
110 Correct 389 ms 41656 KB Output is correct
111 Correct 437 ms 42676 KB Output is correct
112 Correct 403 ms 43148 KB Output is correct
113 Correct 400 ms 43196 KB Output is correct
114 Correct 397 ms 42168 KB Output is correct
115 Correct 402 ms 44212 KB Output is correct
116 Correct 515 ms 55008 KB Output is correct