13102022-04-18 20:45:10Valaki2Házakcpp14Accepted 100/100148ms35948 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

struct Point {
    int x, y;
    Point() : x(0), y(0) {}
    Point(int x_, int y_) : x(x_), y(y_) {}
};

struct House {
    Point a, b;
    int id;
    House() : a(), b(), id(-1) {}
    House(Point a_, Point b_, int id_) : a(a_), b(b_), id(id_) {}
};

struct Event {
    // -1: kivenni
    // 1: berakni
    Point where;
    int id, type;
    Event() : where(), id(-1), type(0) {}
    Event(Point where_, int id_, int type_)
        : where(where_), id(id_), type(type_) {}
};

int sg(int x) {
    if(x < 0) {
        return -1;
    }
    if(x == 0) {
        return 0;
    }
    if(x > 0) {
        return 1;
    }
}

int direction(Point a, Point b, Point c) {
    return sg((b.y - a.y) * (c.x - a.x) - (c.y - a.y) * (b.x - a.x));
}

bool between(Point a, Point b, Point c) {
    return (c.x >= min(a.x, b.x)) && (c.x <= max(a.x, b.x)) && (c.y >= min(a.y, b.y)) && (c.y <= max(a.y, b.y));
}

Point origo;

bool polarsort(Event a, Event b) {
    int dir = direction(origo, a.where, b.where);
    if(dir == -1) {
        return false;
    }
    if(dir == 1) {
        return true;
    }
    return between(origo, b.where, a.where);
}

int n;
vector<House> houses;
vector<Event> events;

struct msort {
    bool operator()(const House &a, const House &b) const {
        return (direction(a.a, a.b, b.a) == -1 && direction(a.a, a.b, b.b) == -1)
            || (direction(b.a, b.b, a.a) == 1 && direction(b.a, b.b, a.b) == 1);
    }
};

multiset<House, msort> m;
vector<bool> ans;

void add(House h) {
    m.insert(h);
}

void rem(House h) {
    m.erase(m.find(h));
}

void query() {
    if(m.empty()) {
        return;
    }
    House h = *m.begin();
    ans[h.id] = true;
}

void solve() {
    origo = Point(0, 0);
    cin >> n;
    houses.assign(n, House(Point(), Point(), -1));
    for(int i = 0; i < n; i++) {
        cin >> houses[i].a.x >> houses[i].b.y >> houses[i].b.x >> houses[i].a.y;
        houses[i].id = i;
        events.pb(Event(houses[i].a, houses[i].id, 1));
        events.pb(Event(houses[i].b, houses[i].id, -1));
    }
    sort(events.begin(), events.end(), polarsort);
    ans.assign(n, false);
    for(int i = 0; i < (int) events.size(); i++) {
        if(events[i].type == -1) {
            rem(houses[events[i].id]);
        } else {
            add(houses[events[i].id]);
        }
        if(i + 1 != (int) events.size()) {
            if(direction(origo, events[i].where, events[i + 1].where) != 0) {
                query();
            }
        }
    }
    int ans_cnt = 0;
    for(int i = 0; i < n; i++) {
        if(ans[i]) {
            ans_cnt++;
        }
    }
    cout << ans_cnt << "\n";
    for(int i = 0; i < n; i++) {
        if(ans[i]) {
            cout << i + 1 << " ";
        }
    }
    cout << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1860 KiB
2Accepted14ms4984 KiB
subtask215/15
3Accepted1ms2224 KiB
4Accepted2ms2560 KiB
5Accepted7ms3864 KiB
6Accepted13ms5432 KiB
7Accepted13ms5772 KiB
subtask315/15
8Accepted1ms2956 KiB
9Accepted1ms2980 KiB
10Accepted2ms3036 KiB
11Accepted2ms3072 KiB
12Accepted2ms3296 KiB
subtask420/20
13Accepted2ms3332 KiB
14Accepted3ms3668 KiB
15Accepted8ms4816 KiB
16Accepted9ms5264 KiB
17Accepted9ms5468 KiB
subtask550/50
18Accepted27ms9752 KiB
19Accepted39ms11284 KiB
20Accepted68ms18288 KiB
21Accepted143ms32776 KiB
22Accepted148ms35948 KiB