QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321607 | #949. Roads | Camillus | 100 ✓ | 179ms | 22760kb | C++23 | 3.4kb | 2024-02-04 23:54:40 | 2024-02-04 23:54:41 |
Judging History
answer
#include "bits/stdc++.h"
using ll = long long;
using ld = long double;
using namespace std;
struct Point {
ll x = 0, y = 0;
Point() = default;
Point(ll x, ll y) : x(x), y(y) {}
Point(const Point &A, const Point &B) {
x = B.x - A.x;
y = B.y - A.y;
}
ll operator%(const Point &other) const {
return x * other.y -y * other.x;
}
ll operator*(const Point &other) const {
return x * other.x + y * other.y;
}
bool operator<(const Point &other) const {
return y < other.y || (y == other.y && x < other.x);
}
bool operator==(const Point &other) const {
return x == other.x && y == other.y;
}
bool operator!=(const Point &other) const {
return !this->operator==(other);
}
Point operator+(const Point &other) const {
return {x + other.x, y + other.y};
}
friend istream& operator>>(istream &in, Point &other) {
return in >> other.x >> other.y;
}
friend ostream& operator<<(ostream &out, const Point &other) {
return out << other.x << ' ' << other.y;
}
};
struct Frac {
__int128 a = 0, b = 1;
Frac() {}
Frac(__int128 a, __int128 b) : a(a), b(b) {}
bool operator<(const Frac &other) const {
return a * other.b < b * other.a;
}
};
struct Line {
__int128 a = 0, b = 1, c = 0;
Line() = default;
Line(const Point &A, const Point &B) {
a = A.y - B.y;
b = B.x - A.x;
c = -(a * A.x + b * A.y);
}
Frac y(const Line &other) const {
return Frac(c * other.a - other.c * a, a * other.b - other.a * b);
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
static constexpr int INF = 100'000'000;
Point V(Point(0, 0), Point(1, INF));
Point H(Point(0, 0), Point(INF, -1));
vector<pair<Point, Point>> S(n + 1);
map<ll, pair<int, bool>> M;
for (int i = 0; i < n; i++) {
cin >> S[i].first >> S[i].second;
if (H * S[i].first > H * S[i].second) {
swap(S[i].first, S[i].second);
}
M[H * S[i].first] = pair(i, false);
M[H * S[i].second] = pair(i, true);
}
Point current;
auto getY = [&](int i) {
Line C(current, current + V);
return C.y(Line(S[i].first, S[i].second));
};
auto comp = [&](int i, int j) -> bool {
if (i == n) {
return (j != n);
}
if (j == n) {
return false;
}
return getY(i) < getY(j);
};
set<int, decltype(comp)> Q(comp);
S[n] = pair(Point(-INF, -INF), Point(INF, -INF - 2));
Q.insert(n);
vector<Point> T(n + 1);
T[n] = S[n].first;
for (auto [x, p] : M) {
auto [i, closed] = p;
if (closed) {
current = S[i].second;
auto it = Q.find(i);
int j = *prev(it);
T[j] = S[i].second;
Q.erase(it);
} else {
current = S[i].first;
auto it = Q.insert(i).first;
int j = *prev(it);
if (T[j] != S[n].first) {
cout << T[j] << ' ' << S[i].first << '\n';
}
T[i] = S[i].first;
T[j] = S[i].first;
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Accepted
Test #1:
score: 0
Accepted
time: 0ms
memory: 3604kb
Test #2:
score: 0
Accepted
time: 44ms
memory: 9136kb
Subtask #2:
score: 15
Accepted
Test #3:
score: 15
Accepted
time: 1ms
memory: 3808kb
Test #4:
score: 0
Accepted
time: 1ms
memory: 3616kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3784kb
Test #6:
score: 0
Accepted
time: 9ms
memory: 4932kb
Test #7:
score: 0
Accepted
time: 21ms
memory: 6520kb
Subtask #3:
score: 15
Accepted
Test #8:
score: 15
Accepted
time: 1ms
memory: 3556kb
Test #9:
score: 0
Accepted
time: 1ms
memory: 3576kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 3728kb
Test #11:
score: 0
Accepted
time: 12ms
memory: 4900kb
Test #12:
score: 0
Accepted
time: 179ms
memory: 20156kb
Subtask #4:
score: 15
Accepted
Test #13:
score: 15
Accepted
time: 1ms
memory: 3592kb
Test #14:
score: 0
Accepted
time: 1ms
memory: 3616kb
Test #15:
score: 0
Accepted
time: 1ms
memory: 3776kb
Test #16:
score: 0
Accepted
time: 6ms
memory: 4952kb
Test #17:
score: 0
Accepted
time: 54ms
memory: 11752kb
Subtask #5:
score: 15
Accepted
Test #18:
score: 15
Accepted
time: 1ms
memory: 3500kb
Test #19:
score: 0
Accepted
time: 0ms
memory: 3760kb
Test #20:
score: 0
Accepted
time: 1ms
memory: 3660kb
Test #21:
score: 0
Accepted
time: 1ms
memory: 3576kb
Test #22:
score: 0
Accepted
time: 1ms
memory: 3656kb
Test #23:
score: 0
Accepted
time: 1ms
memory: 3560kb
Test #24:
score: 0
Accepted
time: 1ms
memory: 3748kb
Test #25:
score: 0
Accepted
time: 0ms
memory: 3620kb
Test #26:
score: 0
Accepted
time: 4ms
memory: 4220kb
Test #27:
score: 0
Accepted
time: 5ms
memory: 4208kb
Test #28:
score: 0
Accepted
time: 3ms
memory: 4536kb
Subtask #6:
score: 40
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #29:
score: 40
Accepted
time: 84ms
memory: 15104kb
Test #30:
score: 0
Accepted
time: 109ms
memory: 18832kb
Test #31:
score: 0
Accepted
time: 1ms
memory: 3752kb
Test #32:
score: 0
Accepted
time: 89ms
memory: 13852kb
Test #33:
score: 0
Accepted
time: 93ms
memory: 13976kb
Test #34:
score: 0
Accepted
time: 140ms
memory: 17340kb
Test #35:
score: 0
Accepted
time: 123ms
memory: 17940kb
Test #36:
score: 0
Accepted
time: 135ms
memory: 22760kb
Extra Test:
score: 0
Extra Test Passed