QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#764160 | #6734. Click the Circle | maspy | AC ✓ | 2903ms | 7960kb | C++23 | 25.0kb | 2024-11-20 01:47:51 | 2024-11-20 01:47:53 |
Judging History
answer
#line 1 "/home/maspy/compro/library/my_template.hpp"
#if defined(LOCAL)
#include <my_template_compiled.hpp>
#else
// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("Ofast,unroll-loops")
// いまの CF だとこれ入れると動かない?
// #pragma GCC target("avx2,popcnt")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'010'000'000;
template <>
constexpr ll infty<ll> = 2'020'000'000'000'000'000;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * 2'000'000'000'000'000'000;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...) \
vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
// https://trap.jp/post/1224/
#define FOR1(a) for (ll _ = 0; _ < ll(a); ++_)
#define FOR2(i, a) for (ll i = 0; i < ll(a); ++i)
#define FOR3(i, a, b) for (ll i = a; i < ll(b); ++i)
#define FOR4(i, a, b, c) for (ll i = a; i < ll(b); i += (c))
#define FOR1_R(a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR2_R(i, a) for (ll i = (a)-1; i >= ll(0); --i)
#define FOR3_R(i, a, b) for (ll i = (b)-1; i >= ll(a); --i)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FOR_R(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define FOR_subset(t, s) for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define elif else if
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define stoi stoll
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_sgn(int x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u32 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(ll x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
int popcnt_sgn(u64 x) { return (__builtin_parity(x) & 1 ? -1 : 1); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T kth_bit(int k) {
return T(1) << k;
}
template <typename T>
bool has_kth_bit(T x, int k) {
return x >> k & 1;
}
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <typename T, typename U>
T SUM(const vector<U> &A) {
T sm = 0;
for (auto &&a: A) sm += a;
return sm;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()
template <typename T>
T POP(deque<T> &que) {
T a = que.front();
que.pop_front();
return a;
}
template <typename T>
T POP(pq<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(pqg<T> &que) {
T a = que.top();
que.pop();
return a;
}
template <typename T>
T POP(vc<T> &que) {
T a = que.back();
que.pop_back();
return a;
}
template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
if (check_ok) assert(check(ok));
while (abs(ok - ng) > 1) {
auto x = (ng + ok) / 2;
(check(x) ? ok : ng) = x;
}
return ok;
}
template <typename F>
double binary_search_real(F check, double ok, double ng, int iter = 100) {
FOR(iter) {
double x = (ok + ng) / 2;
(check(x) ? ok : ng) = x;
}
return (ok + ng) / 2;
}
template <class T, class S>
inline bool chmax(T &a, const S &b) {
return (a < b ? a = b, 1 : 0);
}
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
vc<int> A(S.size());
FOR(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
return A;
}
template <typename T, typename U>
vector<T> cumsum(vector<U> &A, int off = 1) {
int N = A.size();
vector<T> B(N + 1);
FOR(i, N) { B[i + 1] = B[i] + A[i]; }
if (off == 0) B.erase(B.begin());
return B;
}
// stable sort
template <typename T>
vector<int> argsort(const vector<T> &A) {
vector<int> ids(len(A));
iota(all(ids), 0);
sort(all(ids), [&](int i, int j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
return ids;
}
// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vc<int> &I) {
vc<T> B(len(I));
FOR(i, len(I)) B[i] = A[I[i]];
return B;
}
template <typename T, typename... Vectors>
void concat(vc<T> &first, const Vectors &... others) {
vc<T> &res = first;
(res.insert(res.end(), others.begin(), others.end()), ...);
}
#endif
#line 1 "/home/maspy/compro/library/other/io.hpp"
#define FASTIO
#include <unistd.h>
// https://judge.yosupo.jp/submission/21623
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memcpy(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ) ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir) load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir) load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T>
void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T>
void rd_integer(T &x) {
if (pil + 100 > pir) load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') { minus = 1, c = ibuf[pil++]; }
}
x = 0;
while ('0' <= c) { x = x * 10 + (c & 15), c = ibuf[pil++]; }
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus) x = -x;
}
}
void rd(int &x) { rd_integer(x); }
void rd(ll &x) { rd_integer(x); }
void rd(i128 &x) { rd_integer(x); }
void rd(u32 &x) { rd_integer(x); }
void rd(u64 &x) { rd_integer(x); }
void rd(u128 &x) { rd_integer(x); }
void rd(double &x) { rd_real(x); }
void rd(long double &x) { rd_real(x); }
void rd(f128 &x) { rd_real(x); }
template <class T, class U>
void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T>
void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T>
void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T>
void rd(array<T, N> &x) {
for (auto &d: x) rd(d);
}
template <class T>
void rd(vc<T> &x) {
for (auto &d: x) rd(d);
}
void read() {}
template <class H, class... T>
void read(H &h, T &... t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ) flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c: s) wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) wt(s[i]);
}
template <typename T>
void wt_integer(T x) {
if (por > SZ - 100) flush();
if (x < 0) { obuf[por++] = '-', x = -x; }
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T>
void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) { wt_integer(x); }
void wt(ll x) { wt_integer(x); }
void wt(i128 x) { wt_integer(x); }
void wt(u32 x) { wt_integer(x); }
void wt(u64 x) { wt_integer(x); }
void wt(u128 x) { wt_integer(x); }
void wt(double x) { wt_real(x); }
void wt(long double x) { wt_real(x); }
void wt(f128 x) { wt_real(x); }
template <class T, class U>
void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) { wt(' '); }
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T>
void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
template <class T>
void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i) wt(' ');
wt(val[i]);
}
}
void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
wt(head);
if (sizeof...(Tail)) wt(' ');
print(forward<Tail>(tail)...);
}
// gcc expansion. called automaticall after main.
void __attribute__((destructor)) _d() { flush(); }
} // namespace fastio
using fastio::read;
using fastio::print;
using fastio::flush;
#if defined(LOCAL)
#define SHOW(...) SHOW_IMPL(__VA_ARGS__, SHOW6, SHOW5, SHOW4, SHOW3, SHOW2, SHOW1)(__VA_ARGS__)
#define SHOW_IMPL(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define SHOW1(x) print(#x, "=", (x)), flush()
#define SHOW2(x, y) print(#x, "=", (x), #y, "=", (y)), flush()
#define SHOW3(x, y, z) print(#x, "=", (x), #y, "=", (y), #z, "=", (z)), flush()
#define SHOW4(x, y, z, w) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w)), flush()
#define SHOW5(x, y, z, w, v) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v)), flush()
#define SHOW6(x, y, z, w, v, u) print(#x, "=", (x), #y, "=", (y), #z, "=", (z), #w, "=", (w), #v, "=", (v), #u, "=", (u)), flush()
#else
#define SHOW(...)
#endif
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define U32(...) \
u32 __VA_ARGS__; \
read(__VA_ARGS__)
#define U64(...) \
u64 __VA_ARGS__; \
read(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
read(name)
void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
#line 3 "main.cpp"
#line 2 "/home/maspy/compro/library/geo/base.hpp"
template <typename T>
struct Point {
T x, y;
Point() : x(0), y(0) {}
template <typename A, typename B>
Point(A x, B y) : x(x), y(y) {}
template <typename A, typename B>
Point(pair<A, B> p) : x(p.fi), y(p.se) {}
Point operator+=(const Point p) {
x += p.x, y += p.y;
return *this;
}
Point operator-=(const Point p) {
x -= p.x, y -= p.y;
return *this;
}
Point operator+(Point p) const { return {x + p.x, y + p.y}; }
Point operator-(Point p) const { return {x - p.x, y - p.y}; }
bool operator==(Point p) const { return x == p.x && y == p.y; }
bool operator!=(Point p) const { return x != p.x || y != p.y; }
Point operator-() const { return {-x, -y}; }
Point operator*(T t) const { return {x * t, y * t}; }
Point operator/(T t) const { return {x / t, y / t}; }
bool operator<(Point p) const {
if (x != p.x) return x < p.x;
return y < p.y;
}
T dot(const Point& other) const { return x * other.x + y * other.y; }
T det(const Point& other) const { return x * other.y - y * other.x; }
double norm() { return sqrtl(x * x + y * y); }
double angle() { return atan2(y, x); }
Point rotate(double theta) {
static_assert(!is_integral<T>::value);
double c = cos(theta), s = sin(theta);
return Point{c * x - s * y, s * x + c * y};
}
Point rot90(bool ccw) { return (ccw ? Point{-y, x} : Point{y, -x}); }
};
#ifdef FASTIO
template <typename T>
void rd(Point<T>& p) {
fastio::rd(p.x), fastio::rd(p.y);
}
template <typename T>
void wt(Point<T>& p) {
fastio::wt(p.x);
fastio::wt(' ');
fastio::wt(p.y);
}
#endif
// A -> B -> C と進むときに、左に曲がるならば +1、右に曲がるならば -1
template <typename T>
int ccw(Point<T> A, Point<T> B, Point<T> C) {
T x = (B - A).det(C - A);
if (x > 0) return 1;
if (x < 0) return -1;
return 0;
}
template <typename REAL, typename T, typename U>
REAL dist(Point<T> A, Point<U> B) {
REAL dx = REAL(A.x) - REAL(B.x);
REAL dy = REAL(A.y) - REAL(B.y);
return sqrt(dx * dx + dy * dy);
}
// ax+by+c
template <typename T>
struct Line {
T a, b, c;
Line(T a, T b, T c) : a(a), b(b), c(c) {}
Line(Point<T> A, Point<T> B) { a = A.y - B.y, b = B.x - A.x, c = A.x * B.y - A.y * B.x; }
Line(T x1, T y1, T x2, T y2) : Line(Point<T>(x1, y1), Point<T>(x2, y2)) {}
template <typename U>
U eval(Point<U> P) {
return a * P.x + b * P.y + c;
}
template <typename U>
T eval(U x, U y) {
return a * x + b * y + c;
}
// 同じ直線が同じ a,b,c で表現されるようにする
void normalize() {
static_assert(is_same_v<T, int> || is_same_v<T, long long>);
T g = gcd(gcd(abs(a), abs(b)), abs(c));
a /= g, b /= g, c /= g;
if (b < 0) { a = -a, b = -b, c = -c; }
if (b == 0 && a < 0) { a = -a, b = -b, c = -c; }
}
bool is_parallel(Line other) { return a * other.b - b * other.a == 0; }
bool is_orthogonal(Line other) { return a * other.a + b * other.b == 0; }
};
template <typename T>
struct Segment {
Point<T> A, B;
Segment(Point<T> A, Point<T> B) : A(A), B(B) {}
Segment(T x1, T y1, T x2, T y2) : Segment(Point<T>(x1, y1), Point<T>(x2, y2)) {}
bool contain(Point<T> C) {
T det = (C - A).det(B - A);
if (det != 0) return 0;
return (C - A).dot(B - A) >= 0 && (C - B).dot(A - B) >= 0;
}
Line<T> to_Line() { return Line(A, B); }
};
template <typename REAL>
struct Circle {
Point<REAL> O;
REAL r;
Circle(Point<REAL> O, REAL r) : O(O), r(r) {}
Circle(REAL x, REAL y, REAL r) : O(x, y), r(r) {}
template <typename T>
bool contain(Point<T> p) {
REAL dx = p.x - O.x, dy = p.y - O.y;
return dx * dx + dy * dy <= r * r;
}
};
#line 2 "/home/maspy/compro/library/geo/cross_point.hpp"
#line 4 "/home/maspy/compro/library/geo/cross_point.hpp"
// 平行でないことを仮定
template <typename REAL, typename T>
Point<REAL> cross_point(const Line<T> L1, const Line<T> L2) {
T det = L1.a * L2.b - L1.b * L2.a;
assert(det != 0);
REAL x = -REAL(L1.c) * L2.b + REAL(L1.b) * L2.c;
REAL y = -REAL(L1.a) * L2.c + REAL(L1.c) * L2.a;
return Point<REAL>(x / det, y / det);
}
// 浮動小数点数はエラー
// 0: 交点なし
// 1: 一意な交点
// 2:2 つ以上の交点(整数型を利用して厳密にやる)
template <typename T>
int count_cross(Segment<T> S1, Segment<T> S2, bool include_ends) {
static_assert(!std::is_floating_point<T>::value);
Line<T> L1 = S1.to_Line();
Line<T> L2 = S2.to_Line();
if (L1.is_parallel(L2)) {
if (L1.eval(S2.A) != 0) return 0;
// 4 点とも同一直線上にある
T a1 = S1.A.x, b1 = S1.B.x;
T a2 = S2.A.x, b2 = S2.B.x;
if (a1 == b1) {
a1 = S1.A.y, b1 = S1.B.y;
a2 = S2.A.y, b2 = S2.B.y;
}
if (a1 > b1) swap(a1, b1);
if (a2 > b2) swap(a2, b2);
T a = max(a1, a2);
T b = min(b1, b2);
if (a < b) return 2;
if (a > b) return 0;
return (include_ends ? 1 : 0);
}
// 平行でない場合
T a1 = L2.eval(S1.A), b1 = L2.eval(S1.B);
T a2 = L1.eval(S2.A), b2 = L1.eval(S2.B);
if (a1 > b1) swap(a1, b1);
if (a2 > b2) swap(a2, b2);
bool ok1 = 0, ok2 = 0;
if (include_ends) {
ok1 = (a1 <= T(0)) && (T(0) <= b1);
ok2 = (a2 <= T(0)) && (T(0) <= b2);
} else {
ok1 = (a1 < T(0)) && (T(0) < b1);
ok2 = (a2 < T(0)) && (T(0) < b2);
}
return (ok1 && ok2 ? 1 : 0);
}
// https://codeforces.com/contest/607/problem/E
template <typename REAL, typename T>
vc<Point<REAL>> cross_point(const Circle<T> C, const Line<T> L) {
T a = L.a, b = L.b, c = L.a * (C.O.x) + L.b * (C.O.y) + L.c;
T r = C.r;
bool SW = 0;
if (abs(a) < abs(b)) {
swap(a, b);
SW = 1;
}
// ax+by+c=0, x^2+y^2=r^2
T D = 4 * c * c * b * b - 4 * (a * a + b * b) * (c * c - a * a * r * r);
if (D < 0) return {};
REAL sqD = sqrtl(D);
REAL y1 = (-2 * b * c + sqD) / (2 * (a * a + b * b));
REAL y2 = (-2 * b * c - sqD) / (2 * (a * a + b * b));
REAL x1 = (-b * y1 - c) / a;
REAL x2 = (-b * y2 - c) / a;
if (SW) swap(x1, y1), swap(x2, y2);
x1 += C.O.x, x2 += C.O.x;
y1 += C.O.y, y2 += C.O.y;
if (D == 0) return {Point<REAL>(x1, y1)};
return {Point<REAL>(x1, y1), Point<REAL>(x2, y2)};
}
// https://codeforces.com/contest/2/problem/C
template <typename REAL, typename T>
tuple<bool, Point<T>, Point<T>> cross_point_circle(Circle<T> C1, Circle<T> C2) {
using P = Point<T>;
P O{0, 0};
P A = C1.O, B = C2.O;
if (A == B) return {false, O, O};
T d = (B - A).norm();
REAL cos_val = (C1.r * C1.r + d * d - C2.r * C2.r) / (2 * C1.r * d);
if (cos_val < -1 || 1 < cos_val) return {false, O, O};
REAL t = acos(cos_val);
REAL u = (B - A).angle();
P X = A + P{C1.r * cos(u + t), C1.r * sin(u + t)};
P Y = A + P{C1.r * cos(u - t), C1.r * sin(u - t)};
return {true, X, Y};
}
#line 2 "/home/maspy/compro/library/geo/distance.hpp"
template <typename REAL, typename T, typename U>
REAL distance(Point<T> S, Point<U> P) {
REAL dx = P.x - S.x;
REAL dy = P.y - S.y;
return sqrt(dx * dx + dy * dy);
}
template <typename REAL, typename T, typename U>
REAL distance(Segment<T> S, Point<U> P) {
Point<T> A = S.A, B = S.B;
bool b1 = (B - A).dot(P - A) >= 0;
bool b2 = (A - B).dot(P - B) >= 0;
if (b1 && !b2) { return distance<REAL, T, T>(B, P); }
if (!b1 && b2) { return distance<REAL, T, T>(A, P); }
Line<T> L = S.to_Line();
// 点と直線の距離
return REAL(abs(L.eval(P))) / sqrt(REAL(L.a) * L.a + REAL(L.b) * L.b);
}
template <typename REAL, typename T>
REAL distance(Segment<T> S1, Segment<T> S2) {
if (count_cross<T>(S1, S2, true)) return REAL(0);
REAL res = distance<REAL, T, T>(S1, S2.A);
chmin(res, distance<REAL, T, T>(S1, S2.B));
chmin(res, distance<REAL, T, T>(S2, S1.A));
chmin(res, distance<REAL, T, T>(S2, S1.B));
return res;
}
template <typename REAL, typename T>
REAL distance(Point<T> P, Line<T> L) {
return abs(L.a * P.x + L.b * P.y + L.c) / sqrt(L.a * L.a + L.b * L.b);
}
#line 1 "/home/maspy/compro/library/other/golden_search.hpp"
// return : (fx, x)
// f が評価される回数:2 + iter
// 幅が 1/phi^{iter} 倍になる. iter = 44: 1e-9.
template <typename Re, bool MINIMIZE, typename F>
pair<Re, Re> golden_search(F f, Re lx, Re rx, int iter = 50) {
assert(lx <= rx);
Re inv_phi = (sqrtl(5) - 1.0) * 0.5;
Re inv_phi_2 = inv_phi * inv_phi;
Re x1 = lx, x4 = rx;
Re x2 = x1 + inv_phi_2 * (x4 - x1);
Re x3 = x1 + inv_phi * (x4 - x1);
Re y2 = f(x2), y3 = f(x3);
auto comp = [&](Re a, Re b) -> bool {
if constexpr (MINIMIZE)
return a < b;
else
return a > b;
};
FOR(iter) {
if (comp(y2, y3)) {
x4 = x3, x3 = x2, y3 = y2;
x2 = x1 + inv_phi_2 * (x4 - x1);
y2 = f(x2);
} else {
x1 = x2, x2 = x3, y2 = y3;
x3 = x1 + inv_phi * (x4 - x1);
y3 = f(x3);
}
}
return (comp(y2, y3) ? pair<Re, Re>{y2, x2} : pair<Re, Re>{y3, x3});
}
#line 7 "main.cpp"
using Re = long double;
using P = Point<Re>;
// Frame とは線分かと思っていたが、円の和集合か??
struct C {
int idx;
ll s, t;
P A, B;
P get(Re x) {
Re a = t - x, b = x - s;
a /= t - s, b /= t - s;
return A * a + B * b;
}
};
struct S {
int idx;
ll s, t;
P A, B;
};
bool ANS[1 << 11][1 << 11];
Re eps = 1e-12;
void solve() {
LL(N, R, D);
vc<C> Cs;
vc<S> Ss;
int n = 0;
FOR(i, N) {
INT(t);
if (t == 1) {
LL(cx, cy, t);
P p(cx, cy);
Cs.eb(n, t - D, t + D, p, p);
n++;
}
if (t == 2) {
LL(sx, sy, tx, ty, u, v);
P A(sx, sy), B(tx, ty);
Cs.eb(n, u - D, u, A, A);
Cs.eb(n, u, v, A, B);
Cs.eb(n, v, v + D, B, B);
n++;
Ss.eb(n, u - D, v + D, A, B);
n++;
}
}
auto CC = [&](C X, C Y) -> bool {
ll s = max(X.s, Y.s);
ll t = min(X.t, Y.t);
if (s > t) return 0;
auto f = [&](Re t) -> Re {
P p = X.get(t);
P q = Y.get(t);
return (p - q).dot(p - q);
};
auto [fx, x] = golden_search<Re, 1>(f, s, t);
fx = sqrtl(max<Re>(fx, 0));
SHOW(fx, 2 * R);
return fx <= 2 * R + eps;
};
auto CS = [&](C X, S Y) -> bool {
ll s = max(X.s, Y.s);
ll t = min(X.t, Y.t);
if (s > t) return 0;
Segment<Re> S(Y.A, Y.B);
auto f = [&](Re t) -> Re {
P p = X.get(t);
return distance<Re>(S, p);
};
auto [fx, x] = golden_search<Re, 1>(f, s, t);
SHOW(fx, R);
return fx <= 2 * R + eps;
};
auto SS = [&](S X, S Y) -> bool {
ll s = max(X.s, Y.s);
ll t = min(X.t, Y.t);
if (s > t) return 0;
Point<ll> XA(X.A.x, X.A.y);
Point<ll> XB(X.B.x, X.B.y);
Point<ll> YA(Y.A.x, Y.A.y);
Point<ll> YB(Y.B.x, Y.B.y);
Segment<ll> S1(XA, XB);
Segment<ll> S2(YA, YB);
Re d = distance<Re>(S1, S2);
return d <= 2 * R + eps;
};
int N1 = len(Cs), N2 = len(Ss);
FOR(i, N1) FOR(j, i) {
C X = Cs[i], Y = Cs[j];
if (X.idx == Y.idx) continue;
if (CC(X, Y)) ANS[X.idx][Y.idx] = 1;
}
FOR(i, N1) FOR(j, N2) {
C X = Cs[i];
S Y = Ss[j];
if (X.idx == Y.idx) continue;
if (CS(X, Y)) ANS[X.idx][Y.idx] = 1;
}
FOR(i, N2) FOR(j, i) {
S X = Ss[i];
S Y = Ss[j];
if (X.idx == Y.idx) continue;
if (SS(X, Y)) ANS[X.idx][Y.idx] = 1;
}
ll ans = 0;
FOR(i, n) FOR(j, i) {
if (ANS[i][j] || ANS[j][i]) ++ans;
}
print(ans);
}
signed main() { solve(); }
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
input:
2 1 1 1 1 1 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
2 1 1 1 1 1 2 1 3 2 3
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
2 1 1 1 3 3 2 2 5 5 5 1 2 4
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
2 1 1 2 1 1 1 5 2 4 2 5 5 5 1 2 4
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
2 1 1 2 10 1 10 20 2 4 2 1 10 20 10 2 4
output:
6
result:
ok 1 number(s): "6"
Test #6:
score: 0
Accepted
time: 278ms
memory: 7208kb
input:
1000 8 4 1 8323 2820 943 1 8246 2850 944 1 8177 2880 941 1 8154 2866 944 2 8325 8146 2865 2846 943 944 1 8349 2891 939 2 8176 8344 2888 2692 940 945 1 8191 2732 945 1 8144 2668 945 2 8182 8191 2889 2844 939 940 1 8173 2687 941 1 8241 2870 945 2 8266 8344 2910 2667 942 943 1 8169 2863 939 1 8349 2921...
output:
22721
result:
ok 1 number(s): "22721"
Test #7:
score: 0
Accepted
time: 308ms
memory: 7956kb
input:
1000 35 8 2 1037 1102 9971 9940 531 534 1 301 9951 548 1 944 9962 529 1 592 9968 537 1 262 9949 531 1 312 9971 553 1 1139 9938 550 2 325 747 9967 9970 539 544 1 810 9941 536 2 906 486 9956 9953 550 552 1 1121 9940 543 2 515 1199 9965 9953 548 552 2 537 926 9972 9949 538 547 1 1356 9967 550 1 332 996...
output:
34559
result:
ok 1 number(s): "34559"
Test #8:
score: 0
Accepted
time: 494ms
memory: 7960kb
input:
1000 472 14 1 3783 7912 938 1 3307 7801 773 1 4605 7852 592 1 2999 7886 644 1 5308 7914 865 1 4978 7842 611 2 3205 5292 7915 7915 724 835 1 6173 7919 846 2 3130 4833 7921 7853 893 906 1 3449 7854 938 2 4951 3238 7824 7897 720 874 2 4842 5378 7906 7913 683 853 2 4991 4467 7906 7830 580 779 2 5782 615...
output:
103238
result:
ok 1 number(s): "103238"
Test #9:
score: 0
Accepted
time: 680ms
memory: 6904kb
input:
1000 4 51 2 6933 7307 7777 7798 450 456 2 6444 6705 7787 7794 447 460 1 7192 7784 464 2 7865 6422 7791 7797 451 460 1 7366 7794 461 2 7364 6214 7785 7782 449 454 2 7378 7099 7801 7798 450 461 2 7961 6794 7784 7788 448 449 2 6510 7007 7787 7797 453 458 1 6517 7786 446 2 6725 7216 7797 7788 451 452 2 ...
output:
36558
result:
ok 1 number(s): "36558"
Test #10:
score: 0
Accepted
time: 310ms
memory: 7328kb
input:
1000 27 6 2 3760 3746 1523 1749 339 366 2 3738 3746 1688 1609 334 356 1 3754 1559 349 1 3761 1551 347 2 3746 3755 1667 1528 338 340 2 3754 3749 1565 1664 331 356 2 3746 3759 1653 1674 357 362 2 3753 3739 1741 1625 346 359 2 3763 3747 1701 1738 340 343 2 3742 3754 1695 1759 361 366 2 3742 3752 1654 1...
output:
36245
result:
ok 1 number(s): "36245"
Test #11:
score: 0
Accepted
time: 1100ms
memory: 7288kb
input:
1000 78 150 1 6600 430 535 1 6589 476 532 2 6596 6596 430 489 530 533 2 6598 6601 469 470 529 531 1 6597 495 534 1 6597 474 533 2 6592 6599 467 465 536 538 2 6600 6596 460 484 535 537 1 6587 461 529 2 6596 6596 431 485 532 533 1 6597 465 538 2 6591 6597 429 465 530 534 1 6598 439 533 2 6596 6588 458...
output:
92999
result:
ok 1 number(s): "92999"
Test #12:
score: 0
Accepted
time: 2903ms
memory: 7736kb
input:
1000 19 854 1 4584 7521 143 1 4587 7497 142 2 4587 4582 7516 7363 145 147 2 4591 4585 7360 7370 143 147 2 4582 4589 7491 7418 145 147 1 4592 7366 145 2 4587 4585 7402 7375 142 143 2 4584 4585 7392 7516 145 147 2 4584 4587 7383 7502 142 147 1 4583 7462 145 1 4592 7461 146 1 4588 7409 142 2 4591 4590 ...
output:
163887
result:
ok 1 number(s): "163887"
Test #13:
score: 0
Accepted
time: 2824ms
memory: 7592kb
input:
1000 38 834 2 727 740 7904 8009 721 901 2 771 686 7753 7896 707 714 2 790 766 7801 7864 877 919 1 790 7902 874 2 709 686 7990 7998 739 760 1 666 7941 849 2 677 726 8009 7939 810 820 2 679 686 7896 7935 810 923 2 747 718 8018 7963 700 786 1 719 7987 825 1 697 7975 931 1 764 7794 847 1 659 7813 813 1 ...
output:
203301
result:
ok 1 number(s): "203301"
Test #14:
score: 0
Accepted
time: 447ms
memory: 6840kb
input:
1000 767 32 2 615 605 4677 4694 404 408 1 620 4687 421 1 617 4681 452 1 621 4687 436 2 609 608 4698 4678 404 433 2 603 620 4690 4680 391 419 2 604 609 4682 4678 405 428 1 615 4678 443 2 615 611 4678 4698 402 413 1 614 4692 450 2 601 616 4695 4692 441 442 1 614 4674 401 1 617 4697 420 1 606 4698 423 ...
output:
104679
result:
ok 1 number(s): "104679"
Test #15:
score: 0
Accepted
time: 283ms
memory: 7084kb
input:
1000 68 9 1 4226 6175 121 2 4232 4221 5792 5879 82 102 1 4226 6152 69 1 4226 5910 69 2 4238 4242 6314 6215 70 74 1 4233 6208 149 1 4247 5765 162 2 4237 4221 5787 5877 180 192 1 4223 5966 148 1 4221 5925 111 2 4241 4245 6105 6069 173 203 1 4234 6275 108 1 4230 5952 166 1 4247 5925 214 1 4220 6288 192...
output:
43227
result:
ok 1 number(s): "43227"
Test #16:
score: 0
Accepted
time: 2671ms
memory: 6860kb
input:
1000 20 500 2 9234 9242 4563 4578 972 976 2 9230 9142 4582 4551 972 973 1 9207 4564 971 1 9246 4561 973 2 9228 9253 4564 4571 976 977 1 9132 4566 973 2 9207 9273 4564 4582 970 982 2 9182 9172 4552 4583 965 970 2 9241 9248 4561 4564 965 966 1 9160 4570 978 1 9171 4573 978 1 9288 4564 977 2 9124 9209 ...
output:
168341
result:
ok 1 number(s): "168341"
Test #17:
score: 0
Accepted
time: 873ms
memory: 7412kb
input:
1000 479 93 2 3917 4659 8054 8309 907 919 1 3652 8108 917 1 3807 8421 889 1 3809 7956 918 2 5455 6444 8146 7993 888 897 1 3919 8428 896 1 5806 8417 904 1 5003 8284 908 1 4433 8111 900 2 4758 5119 8171 8370 893 917 1 5167 8085 909 2 5355 4401 8243 8214 894 902 2 4998 6113 8049 7961 901 905 2 6438 588...
output:
130628
result:
ok 1 number(s): "130628"
Test #18:
score: 0
Accepted
time: 705ms
memory: 6668kb
input:
1000 9 64 2 4598 4157 749 771 946 951 2 3869 4053 744 756 946 957 1 3637 785 963 2 4680 4023 760 797 949 950 2 3674 3955 743 759 949 951 1 4442 794 951 2 4336 4099 806 743 946 962 1 4544 787 962 2 4316 4548 743 802 956 963 1 3582 768 949 1 4230 794 955 2 4477 4446 778 780 957 958 2 3758 4306 751 781...
output:
35598
result:
ok 1 number(s): "35598"
Test #19:
score: 0
Accepted
time: 488ms
memory: 7552kb
input:
1000 57 27 1 7434 3356 642 2 7427 7433 3355 3354 669 684 2 7432 7435 3353 3354 683 778 1 7424 3356 772 2 7434 7421 3356 3351 727 803 2 7432 7420 3355 3352 672 695 2 7426 7421 3353 3354 630 656 2 7425 7420 3352 3355 696 701 1 7428 3352 720 1 7429 3355 692 1 7433 3353 714 1 7430 3355 838 2 7432 7420 3...
output:
61871
result:
ok 1 number(s): "61871"
Test #20:
score: 0
Accepted
time: 2483ms
memory: 7080kb
input:
1000 883 463 1 2380 6779 801 2 1342 1303 6814 6780 800 801 2 263 1224 6797 6792 801 803 2 623 427 6787 6793 801 803 2 398 2034 6801 6790 802 803 1 1521 6782 800 1 1090 6807 803 1 575 6806 799 2 998 1435 6782 6788 801 803 1 811 6799 800 2 1509 1567 6783 6779 799 800 1 1156 6812 800 1 294 6802 800 1 1...
output:
522826
result:
ok 1 number(s): "522826"
Test #21:
score: 0
Accepted
time: 2383ms
memory: 7328kb
input:
1000 1 430 2 9469 9548 8535 8853 127 180 1 9510 9271 108 1 9417 9255 118 1 9603 9094 127 1 9416 8441 120 2 9591 9501 9100 9100 147 198 2 9413 9551 8606 8240 216 223 2 9506 9525 8715 9157 80 152 1 9559 8977 42 1 9552 9286 54 2 9555 9551 8424 9279 37 131 1 9376 9085 61 2 9488 9543 9140 9374 87 222 2 9...
output:
59834
result:
ok 1 number(s): "59834"
Test #22:
score: 0
Accepted
time: 193ms
memory: 7620kb
input:
1000 49 3 2 8881 8913 1885 2159 225 239 1 8883 1980 245 2 8908 8883 2082 2199 223 254 2 8903 8905 2170 2048 229 247 1 8882 1944 225 1 8910 1844 247 2 8887 8902 2034 2080 232 233 1 8887 2082 250 1 8901 1908 251 2 8899 8884 1884 2112 242 245 1 8889 1914 254 1 8899 2188 250 2 8908 8881 2071 2019 239 24...
output:
24042
result:
ok 1 number(s): "24042"
Test #23:
score: 0
Accepted
time: 2776ms
memory: 7072kb
input:
1000 51 968 1 3531 6961 345 1 4472 7149 357 1 2691 6615 359 2 3325 4548 7314 6828 356 358 2 4801 3905 6987 6647 358 372 1 4974 6876 366 1 4527 6792 344 2 3363 3335 7054 7147 359 365 1 2922 6705 375 1 4487 7293 355 2 3236 4914 6926 6782 346 374 1 4463 6740 369 1 2796 6833 361 1 3969 6830 358 1 4665 7...
output:
274214
result:
ok 1 number(s): "274214"
Test #24:
score: 0
Accepted
time: 320ms
memory: 7324kb
input:
1000 1 10 2 5234 5378 7146 7016 658 806 2 3852 5355 6863 6990 837 883 2 3953 3596 7007 6909 701 756 1 6504 6967 920 2 4033 5760 6873 7090 674 869 2 4163 4267 7178 6938 864 912 1 3622 6948 938 1 5798 7146 824 1 4829 7126 786 1 4400 6989 775 1 4738 6933 854 2 4230 5240 6863 7148 711 796 1 3987 7172 84...
output:
15333
result:
ok 1 number(s): "15333"
Test #25:
score: 0
Accepted
time: 644ms
memory: 7356kb
input:
1000 614 50 2 2448 2538 7136 7095 541 552 1 2348 7052 565 1 2498 7085 554 2 2313 2444 7132 7152 552 564 1 2300 7021 560 1 2289 7066 553 2 2572 2547 7122 7067 551 563 2 2473 2462 7054 7062 556 563 1 2290 7046 553 2 2397 2493 7134 7053 547 550 1 2312 7049 551 2 2595 2448 7085 7113 549 557 2 2432 2314 ...
output:
133247
result:
ok 1 number(s): "133247"