답안 #575919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575919 2022-06-11T17:57:20 Z piOOE Roads (CEOI20_roads) C++17
0 / 100
59 ms 5688 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;
#define int long long

typedef long long ll;
typedef long double ld;
typedef double db;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 100002, infI = 1e9 + 7;

int X[N][2], Y[N][2];

pair<int, int> Rmost[N];
int x_now = -infI;

ld get(int i) {
    if (x_now == X[i][0]) {
        return Y[i][0];
    }
    ld k = (Y[i][0] - Y[i][1]) / (ld) (X[i][0] - X[i][1]);
    ld b = Y[i][0] - X[i][0] * k;
    return k * x_now + b;
}

auto comp = [](int i, int j) {
    return get(i) < get(j);
};

set<int, decltype(comp)> st(comp);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<tuple<int, int, int>> qu;
    for (int i = 0; i < n; ++i) {
        cin >> X[i][0] >> Y[i][0] >> X[i][1] >> Y[i][1];
        if (X[i][0] > X[i][1] || (X[i][0] == X[i][1] && Y[i][0] > Y[i][1])) {
            swap(X[i][0], X[i][1]);
            swap(Y[i][0], Y[i][1]);
        }
        qu.emplace_back(X[i][0], 0, i);
        qu.emplace_back(X[i][1], 1, i);
    }
    fill(all(Rmost), make_pair(-infI, -infI));
    sort(all(qu));
    X[n][0] = -infI, Y[n][0] = -infI;
    X[n][1] = infI, Y[n][1] = -infI;
    X[n + 1][0] = -infI, Y[n + 1][0] = infI;
    X[n + 1][1] = infI, Y[n + 1][1] = infI;
    st.insert(n);
    st.insert(n + 1);
    for (auto [x, tt, i]: qu) {
        x_now = x;
        if (tt == 0) {
            st.insert(i);
            auto it = st.find(i);
            pair<int, int> now = Rmost[*prev(it)];
            Rmost[*prev(it)] = Rmost[i] = {X[i][0], Y[i][0]};
            if (now.first != -infI) {
                cout << now.first << " " << now.second << " " << X[i][0] << " " << Y[i][0] << '\n';
            }
        } else {
            auto it = st.find(i);
            Rmost[*prev(it)] = {X[i][1], Y[i][1]};
            st.erase(i);
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 58 ms 5648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Failed 2 ms 2004 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Failed 2 ms 2004 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Failed 2 ms 2004 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Failed 2 ms 1960 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 59 ms 5688 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Failed 2 ms 2004 KB Condition failed: "pf == Sline.end() || !Cross(S[*pi], S[*pf])"
6 Halted 0 ms 0 KB -