Submission #577721

# Submission time Handle Problem Language Result Execution time Memory
577721 2022-06-15T08:23:16 Z tengiz05 Roads (CEOI20_roads) C++17
0 / 100
655 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

constexpr int inf = 1E9;

int Time;

struct Line {
    int x, y;
    double s;
    pair<int, int> l, r;
    Line() {}
    Line(int x1, int y1, int x2, int y2) {
        x = x1;
        y = y1;
        if (x2 - x1 == 0) {
            s = 0;
        } else {
            s = 1. * (y2 - y1) / (x2 - x1);
        }
        l = r = {x1, y1};
    }
};
double at(const Line x) {
    return x.y + (Time - x.x) * x.s;
}
inline bool operator<(const Line &a, const Line &b) {
    if (at(a) - at(b) < -1e-10)
        return true;
    return false;
}

bool bad(const pair<int, int> &x) {
    return abs(x.first) == inf;
}
Line p[100005];
struct Info {
    int x;
    Info(int x) : x(x) {}
};
bool operator<(const Info &a, const Info &b) {
    return p[a.x] < p[b.x];
}
int main() {
    freopen("input1.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<tuple<int, int, int>> events;
    
    vector<int> X1(n + 2), Y1(n + 2), X2(n + 2), Y2(n + 2);
    
    for (int i = 1; i <= n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (x1 > x2) {
            swap(x1, x2);
            swap(y1, y2);
        } else if (x1 == x2 && y1 > y2) {
            swap(y1, y2);
        }
        events.emplace_back(x1, y1, i);
        events.emplace_back(x2, y2, -i);
        X1[i] = x1;
        Y1[i] = y1;
        X2[i] = x2;
        Y2[i] = y2;
    }
    
    sort(events.begin(), events.end());
    
    set<Info> s;
    p[0] = Line(-inf, -inf, inf, -inf);
    p[n + 1] = Line(-inf, inf, inf, inf);
    
    for (int i = 1; i <= n; i++) {
        p[i] = Line(X1[i], Y1[i], X2[i], Y2[i]);
    }
    s.insert(Info(0));
    s.insert(Info(n + 1));
    
    for (auto [x, y, i] : events) {
        Time = x;
        // cerr << "Checking " << x << " " << y << ", " << i << "\n";
            // for (auto x : s) {
                // cout << at(p[x.x]) << ", ";
            // }
            // cerr << "\nEnded\n";
        // cerr << "Checking " << x << " " << y << ", " << i << "\n";
            // for (auto x : s) {
                // cout << x.x << ", ";
            // }
            // cerr << "\nEnded\n";
        if (i > 0) {
            // cerr << prev(s.lower_bound(Info(i)))->x << ",";
            // cerr << next(s.lower_bound(Info(i)))->x << " ";
            auto &L = p[prev(s.upper_bound(Info(i)))->x];
            auto &R = p[s.upper_bound(Info(i))->x];
            // cerr << "HMM";
            if (!bad(L.r)) {
                cout << x << " " << y << " " << L.r.first << " " << L.r.second << "\n";
            } else if (!bad(R.l)) {
                cout << x << " " << y << " " << R.l.first << " " << R.l.second << "\n";
            } else {
            }
            // cerr << "NO";
            // L.r = {x, y};
            // R.l = {x, y};
            // cerr << "YAY";
            s.insert(Info(i));
            // cerr << "OK\n";
        } else {
            // cerr << "D";
            i = -i;
            // cerr << at(p[i]) << "\n";
            // assert(s.lower_bound(Info(i)) != s.end());
            // assert(s.lower_bound(Info(i))->x == i);
            // cerr << "s";
            // cerr << prev(s.lower_bound(Info(i)))->x << " ";
            // cerr << next(s.lower_bound(Info(i)))->x << " ";
            auto &L = p[prev(s.lower_bound(Info(i)))->x];
            auto &R = p[next(s.lower_bound(Info(i)))->x];
            L.r = {x, y};
            R.l = {x, y};
            s.erase(Info(i));
        }
    }
    
    return 0;
}

Compilation message

roads.cpp: In function 'int main()':
roads.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("input1.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 602 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 617 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 638 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 627 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 655 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 623 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -