Submission #697384

# Submission time Handle Problem Language Result Execution time Memory
697384 2023-02-09T14:35:45 Z elkernos Roads (CEOI20_roads) C++17
100 / 100
189 ms 20040 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

struct P {
    int x, y;
    bool operator<(const P &he) const { return make_pair(x, y) < make_pair(he.x, he.y); }
    void read() { cin >> x >> y; }
};

int sweep_x;
struct S {
    P one, two;
    int id;
    double sweep_y() const
    {
        if (one.x == two.x) return one.y;
        return one.y + (double)(two.y - one.y) * (sweep_x - one.x) / (two.x - one.x);
    }
    bool operator<(const S &he) const { return sweep_y() < he.sweep_y(); }
};

struct E {
    S seg;
    bool is_new;
    P point() const { return is_new ? seg.one : seg.two; }
    bool operator<(const E &he) const { return point() < he.point(); }
};  

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    int cnt = 1;
    vector<E> events;
    for (int i = 1; i <= n; i++) {
        P a, b;
        a.read(), b.read();
        if (!(a < b)) swap(a, b);
        events.push_back(E{S{a, b, cnt}, 1});
        events.push_back(E{S{a, b, cnt}, 0});
        cnt++;
    }
    const int oo = 1e9 + 7;
    set<S> on_line;
    for (auto y : {-oo, +oo}) {
        on_line.insert(S{{-oo, y}, {+oo, y}, cnt});
        cnt++;
    }
    vector<P> lower(cnt, {-oo, -oo}), upper(cnt, {-oo, -oo});
    sort(events.begin(), events.end());
    for (auto &e : events) {
        sweep_x = e.point().x;
        if (e.is_new) {
            auto it = on_line.upper_bound(e.seg);
            P maybe = lower[it->id];
            it--;
            maybe = max(maybe, upper[it->id]);
            if (maybe.x != -oo) cout << maybe.x << " " << maybe.y << " " << e.point().x << " " << e.point().y << '\n';
        }
        if (e.is_new) {
            auto it = on_line.insert(e.seg).first;
            lower[it->id] = upper[it->id] = e.point();
        }
        else on_line.erase(e.seg);
        auto it = on_line.upper_bound(e.seg);
        lower[it->id] = e.point();
        it--;
        upper[it->id] = e.point();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 7496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 13 ms 2372 KB Output is correct
5 Correct 23 ms 4016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 564 KB Output is correct
4 Correct 12 ms 2252 KB Output is correct
5 Correct 24 ms 4108 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 13 ms 2252 KB Output is correct
10 Correct 179 ms 18680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 11 ms 2252 KB Output is correct
5 Correct 24 ms 4012 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 12 ms 2292 KB Output is correct
10 Correct 59 ms 9476 KB Output is correct
11 Correct 0 ms 320 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 12 ms 2252 KB Output is correct
6 Correct 0 ms 324 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 456 KB Output is correct
9 Correct 13 ms 2240 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 13 ms 2244 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 2 ms 420 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 6 ms 964 KB Output is correct
23 Correct 6 ms 968 KB Output is correct
24 Correct 13 ms 1572 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 62 ms 7552 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 13 ms 2244 KB Output is correct
7 Correct 26 ms 4012 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 13 ms 2252 KB Output is correct
12 Correct 189 ms 18664 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 12 ms 2248 KB Output is correct
17 Correct 59 ms 9436 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 464 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 6 ms 972 KB Output is correct
27 Correct 6 ms 976 KB Output is correct
28 Correct 11 ms 1604 KB Output is correct
29 Correct 93 ms 12184 KB Output is correct
30 Correct 123 ms 17280 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 119 ms 12460 KB Output is correct
33 Correct 121 ms 12492 KB Output is correct
34 Correct 163 ms 16596 KB Output is correct
35 Correct 166 ms 17196 KB Output is correct
36 Correct 168 ms 20040 KB Output is correct