#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5+5, INF = 1e18, SQRINF = 1e9;
ll n, R;
ll a[N], b[N], c[N], d[N];
vector<pair<ll, ll>> events;
void read() {
cin >> n >> R;
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i] >> c[i] >> d[i];
}
ll val(ll a, ll b, ll c, ll d, ll t) {
ll r1 = a + (c - a) * t;
ll r2 = b + (d - b) * t;
return min(INF, ((r1>=SQRINF || r1<=-SQRINF)?INF:(r1*r1)) + ((r2>=SQRINF || r2<=-SQRINF)?INF:(r2*r2)));
}
void solve() {
for(int i = 0; i < n; i++) {
pair<ll, ll> ans = {INF, INF};
ll x1, x2, l, r, xx;
ll nom = a[i] * (a[i] - c[i]) + b[i] * (b[i] - d[i]);
ll den = (a[i] - c[i]) * (a[i] - c[i]) + (b[i] - d[i]) * (b[i] - d[i]);
if(nom % den == 0) {
x1 = x2 = nom / den;
} else {
x1 = nom / den;
x2 = x1 + 1;
}
x1 = max(0ll, x1), x2 = max(0ll, x2);
if(val(a[i], b[i], c[i], d[i], x2) < val(a[i], b[i], c[i], d[i], x1)) x1 = x2;
if(val(a[i], b[i], c[i], d[i], x1) > R*R) continue;
xx = INF;
l = 0, r = x1;
while(l <= r) {
ll mid = (l+r)/2;
if(val(a[i], b[i], c[i], d[i], mid) <= R*R)
xx = mid, r = mid-1;
else
l = mid+1;
}
ans.first = xx;
xx = INF;
l = x1, r = 1e9;
while(l <= r) {
ll mid = (l+r)/2;
if(val(a[i], b[i], c[i], d[i], mid) <= R*R)
xx = mid, l = mid+1;
else
r = mid-1;
}
ans.second = xx;
if(ans.first == INF || ans.second == INF) continue;
events.push_back({ans.first, 1});
events.push_back({ans.second+1, -1});
}
sort(events.begin(), events.end());
ll ans = 0, cur = 0, prv = 0;
for(auto e : events) {
cur += e.second;
ans = max(ans, cur);
prv = e.first;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
read();
solve();
return 0;
}
Compilation message
noras.cpp: In function 'void solve()':
noras.cpp:65:23: warning: variable 'prv' set but not used [-Wunused-but-set-variable]
ll ans = 0, cur = 0, prv = 0;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
70 ms |
7788 KB |
Output is correct |
24 |
Correct |
61 ms |
7788 KB |
Output is correct |
25 |
Correct |
56 ms |
7788 KB |
Output is correct |
26 |
Correct |
57 ms |
7788 KB |
Output is correct |
27 |
Correct |
49 ms |
5620 KB |
Output is correct |
28 |
Correct |
57 ms |
7788 KB |
Output is correct |
29 |
Correct |
58 ms |
7776 KB |
Output is correct |
30 |
Correct |
58 ms |
7788 KB |
Output is correct |
31 |
Correct |
59 ms |
7788 KB |
Output is correct |
32 |
Correct |
83 ms |
7792 KB |
Output is correct |
33 |
Correct |
83 ms |
7788 KB |
Output is correct |
34 |
Correct |
89 ms |
7788 KB |
Output is correct |
35 |
Correct |
85 ms |
7788 KB |
Output is correct |
36 |
Correct |
83 ms |
7788 KB |
Output is correct |
37 |
Correct |
54 ms |
5616 KB |
Output is correct |
38 |
Correct |
54 ms |
5616 KB |
Output is correct |
39 |
Correct |
52 ms |
5744 KB |
Output is correct |
40 |
Correct |
54 ms |
5744 KB |
Output is correct |
41 |
Correct |
58 ms |
5772 KB |
Output is correct |
42 |
Correct |
51 ms |
5616 KB |
Output is correct |
43 |
Correct |
172 ms |
14964 KB |
Output is correct |
44 |
Correct |
176 ms |
14944 KB |
Output is correct |
45 |
Correct |
173 ms |
14944 KB |
Output is correct |
46 |
Correct |
176 ms |
14944 KB |
Output is correct |
47 |
Correct |
172 ms |
14944 KB |
Output is correct |
48 |
Correct |
161 ms |
14948 KB |
Output is correct |
49 |
Correct |
154 ms |
14940 KB |
Output is correct |
50 |
Correct |
154 ms |
14944 KB |
Output is correct |
51 |
Correct |
155 ms |
14948 KB |
Output is correct |
52 |
Correct |
157 ms |
14948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
0 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
70 ms |
7788 KB |
Output is correct |
24 |
Correct |
61 ms |
7788 KB |
Output is correct |
25 |
Correct |
56 ms |
7788 KB |
Output is correct |
26 |
Correct |
57 ms |
7788 KB |
Output is correct |
27 |
Correct |
49 ms |
5620 KB |
Output is correct |
28 |
Correct |
57 ms |
7788 KB |
Output is correct |
29 |
Correct |
58 ms |
7776 KB |
Output is correct |
30 |
Correct |
58 ms |
7788 KB |
Output is correct |
31 |
Correct |
59 ms |
7788 KB |
Output is correct |
32 |
Correct |
83 ms |
7792 KB |
Output is correct |
33 |
Correct |
83 ms |
7788 KB |
Output is correct |
34 |
Correct |
89 ms |
7788 KB |
Output is correct |
35 |
Correct |
85 ms |
7788 KB |
Output is correct |
36 |
Correct |
83 ms |
7788 KB |
Output is correct |
37 |
Correct |
54 ms |
5616 KB |
Output is correct |
38 |
Correct |
54 ms |
5616 KB |
Output is correct |
39 |
Correct |
52 ms |
5744 KB |
Output is correct |
40 |
Correct |
54 ms |
5744 KB |
Output is correct |
41 |
Correct |
58 ms |
5772 KB |
Output is correct |
42 |
Correct |
51 ms |
5616 KB |
Output is correct |
43 |
Correct |
172 ms |
14964 KB |
Output is correct |
44 |
Correct |
176 ms |
14944 KB |
Output is correct |
45 |
Correct |
173 ms |
14944 KB |
Output is correct |
46 |
Correct |
176 ms |
14944 KB |
Output is correct |
47 |
Correct |
172 ms |
14944 KB |
Output is correct |
48 |
Correct |
161 ms |
14948 KB |
Output is correct |
49 |
Correct |
154 ms |
14940 KB |
Output is correct |
50 |
Correct |
154 ms |
14944 KB |
Output is correct |
51 |
Correct |
155 ms |
14948 KB |
Output is correct |
52 |
Correct |
157 ms |
14948 KB |
Output is correct |
53 |
Correct |
85 ms |
7964 KB |
Output is correct |
54 |
Correct |
52 ms |
5616 KB |
Output is correct |
55 |
Correct |
51 ms |
5616 KB |
Output is correct |
56 |
Correct |
54 ms |
5616 KB |
Output is correct |
57 |
Correct |
58 ms |
5616 KB |
Output is correct |
58 |
Correct |
59 ms |
5616 KB |
Output is correct |
59 |
Correct |
63 ms |
5620 KB |
Output is correct |
60 |
Correct |
59 ms |
5616 KB |
Output is correct |
61 |
Correct |
63 ms |
5744 KB |
Output is correct |
62 |
Correct |
79 ms |
7788 KB |
Output is correct |
63 |
Correct |
79 ms |
7664 KB |
Output is correct |
64 |
Correct |
78 ms |
7788 KB |
Output is correct |
65 |
Correct |
81 ms |
7788 KB |
Output is correct |
66 |
Correct |
79 ms |
7916 KB |
Output is correct |
67 |
Correct |
56 ms |
5616 KB |
Output is correct |
68 |
Correct |
59 ms |
7788 KB |
Output is correct |
69 |
Correct |
61 ms |
7788 KB |
Output is correct |
70 |
Correct |
52 ms |
5616 KB |
Output is correct |
71 |
Correct |
167 ms |
14944 KB |
Output is correct |
72 |
Correct |
163 ms |
15076 KB |
Output is correct |
73 |
Correct |
161 ms |
14952 KB |
Output is correct |
74 |
Correct |
172 ms |
14948 KB |
Output is correct |
75 |
Correct |
165 ms |
14992 KB |
Output is correct |
76 |
Correct |
157 ms |
14940 KB |
Output is correct |
77 |
Correct |
159 ms |
14944 KB |
Output is correct |
78 |
Correct |
154 ms |
14944 KB |
Output is correct |
79 |
Correct |
158 ms |
14952 KB |
Output is correct |
80 |
Correct |
155 ms |
14952 KB |
Output is correct |
81 |
Correct |
0 ms |
384 KB |
Output is correct |
82 |
Correct |
1 ms |
512 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
2 ms |
384 KB |
Output is correct |
86 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
70 ms |
7788 KB |
Output is correct |
24 |
Correct |
61 ms |
7788 KB |
Output is correct |
25 |
Correct |
56 ms |
7788 KB |
Output is correct |
26 |
Correct |
57 ms |
7788 KB |
Output is correct |
27 |
Correct |
49 ms |
5620 KB |
Output is correct |
28 |
Correct |
57 ms |
7788 KB |
Output is correct |
29 |
Correct |
58 ms |
7776 KB |
Output is correct |
30 |
Correct |
58 ms |
7788 KB |
Output is correct |
31 |
Correct |
59 ms |
7788 KB |
Output is correct |
32 |
Correct |
83 ms |
7792 KB |
Output is correct |
33 |
Correct |
83 ms |
7788 KB |
Output is correct |
34 |
Correct |
89 ms |
7788 KB |
Output is correct |
35 |
Correct |
85 ms |
7788 KB |
Output is correct |
36 |
Correct |
83 ms |
7788 KB |
Output is correct |
37 |
Correct |
54 ms |
5616 KB |
Output is correct |
38 |
Correct |
54 ms |
5616 KB |
Output is correct |
39 |
Correct |
52 ms |
5744 KB |
Output is correct |
40 |
Correct |
54 ms |
5744 KB |
Output is correct |
41 |
Correct |
58 ms |
5772 KB |
Output is correct |
42 |
Correct |
51 ms |
5616 KB |
Output is correct |
43 |
Correct |
172 ms |
14964 KB |
Output is correct |
44 |
Correct |
176 ms |
14944 KB |
Output is correct |
45 |
Correct |
173 ms |
14944 KB |
Output is correct |
46 |
Correct |
176 ms |
14944 KB |
Output is correct |
47 |
Correct |
172 ms |
14944 KB |
Output is correct |
48 |
Correct |
161 ms |
14948 KB |
Output is correct |
49 |
Correct |
154 ms |
14940 KB |
Output is correct |
50 |
Correct |
154 ms |
14944 KB |
Output is correct |
51 |
Correct |
155 ms |
14948 KB |
Output is correct |
52 |
Correct |
157 ms |
14948 KB |
Output is correct |
53 |
Correct |
85 ms |
7964 KB |
Output is correct |
54 |
Correct |
52 ms |
5616 KB |
Output is correct |
55 |
Correct |
51 ms |
5616 KB |
Output is correct |
56 |
Correct |
54 ms |
5616 KB |
Output is correct |
57 |
Correct |
58 ms |
5616 KB |
Output is correct |
58 |
Correct |
59 ms |
5616 KB |
Output is correct |
59 |
Correct |
63 ms |
5620 KB |
Output is correct |
60 |
Correct |
59 ms |
5616 KB |
Output is correct |
61 |
Correct |
63 ms |
5744 KB |
Output is correct |
62 |
Correct |
79 ms |
7788 KB |
Output is correct |
63 |
Correct |
79 ms |
7664 KB |
Output is correct |
64 |
Correct |
78 ms |
7788 KB |
Output is correct |
65 |
Correct |
81 ms |
7788 KB |
Output is correct |
66 |
Correct |
79 ms |
7916 KB |
Output is correct |
67 |
Correct |
56 ms |
5616 KB |
Output is correct |
68 |
Correct |
59 ms |
7788 KB |
Output is correct |
69 |
Correct |
61 ms |
7788 KB |
Output is correct |
70 |
Correct |
52 ms |
5616 KB |
Output is correct |
71 |
Correct |
167 ms |
14944 KB |
Output is correct |
72 |
Correct |
163 ms |
15076 KB |
Output is correct |
73 |
Correct |
161 ms |
14952 KB |
Output is correct |
74 |
Correct |
172 ms |
14948 KB |
Output is correct |
75 |
Correct |
165 ms |
14992 KB |
Output is correct |
76 |
Correct |
157 ms |
14940 KB |
Output is correct |
77 |
Correct |
159 ms |
14944 KB |
Output is correct |
78 |
Correct |
154 ms |
14944 KB |
Output is correct |
79 |
Correct |
158 ms |
14952 KB |
Output is correct |
80 |
Correct |
155 ms |
14952 KB |
Output is correct |
81 |
Correct |
84 ms |
5616 KB |
Output is correct |
82 |
Correct |
82 ms |
5616 KB |
Output is correct |
83 |
Correct |
78 ms |
5616 KB |
Output is correct |
84 |
Correct |
82 ms |
5616 KB |
Output is correct |
85 |
Correct |
81 ms |
5704 KB |
Output is correct |
86 |
Correct |
89 ms |
5616 KB |
Output is correct |
87 |
Correct |
91 ms |
5616 KB |
Output is correct |
88 |
Correct |
88 ms |
5616 KB |
Output is correct |
89 |
Correct |
99 ms |
5616 KB |
Output is correct |
90 |
Correct |
90 ms |
5616 KB |
Output is correct |
91 |
Correct |
66 ms |
7788 KB |
Output is correct |
92 |
Correct |
66 ms |
7788 KB |
Output is correct |
93 |
Correct |
67 ms |
7788 KB |
Output is correct |
94 |
Correct |
68 ms |
7788 KB |
Output is correct |
95 |
Correct |
67 ms |
7788 KB |
Output is correct |
96 |
Correct |
66 ms |
7788 KB |
Output is correct |
97 |
Correct |
66 ms |
7788 KB |
Output is correct |
98 |
Correct |
66 ms |
7788 KB |
Output is correct |
99 |
Correct |
66 ms |
7788 KB |
Output is correct |
100 |
Correct |
69 ms |
7788 KB |
Output is correct |
101 |
Correct |
0 ms |
384 KB |
Output is correct |
102 |
Correct |
1 ms |
512 KB |
Output is correct |
103 |
Correct |
1 ms |
384 KB |
Output is correct |
104 |
Correct |
1 ms |
384 KB |
Output is correct |
105 |
Correct |
2 ms |
384 KB |
Output is correct |
106 |
Correct |
2 ms |
512 KB |
Output is correct |