12922022-03-30 15:34:44Valaki2Házakcpp14Accepted 100/100145ms31840 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 house {
    int x1, y1, x2, y2;
    int id;
    house() : x1(0), y1(0), x2(0), y2(0) {}
};

struct point {
    int x, y;
    int id;
    point() : x(0), y(0), id(-1) {}
    point(int x_, int y_, int id_) : x(x_), y(y_), id(id_) {}
};

const point origo = point(0, 0, -1);

int n;
vector<house> v;
vector<point> pts;
vector<int> ans;

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

int direction(point a, point b, point c) {
    // right=1, mid=0, left=-1
    // (b.y/b.x)-(c.y/c.x)>0
    // (b.y*c.x)-(c.y*b.x)>0
    // ((b.y-a.y)*(c.x-a.x))-((c.y-a.y)*(b.x-a.x))>0
    return sig(((b.y-a.y)*(c.x-a.x))-((c.y-a.y)*(b.x-a.x)));
}

bool polarsort(point a, point b) {
    int dir = direction(origo, a, b);
    if(dir == 0) {
        return a.x < b.x;
    }
    if(dir == 1) {
        return false;
    } else {
        return true;
    }
}

multiset<int> cur_pts;
vector<bool> in_use;
vector<bool> is_ans;
// multiple with same d --> problem
unordered_map<int, int> id_of;

void add_rem(point p) {
    int d = v[p.id].x1 + v[p.id].y1;
    if(in_use[p.id]) {
        in_use[p.id] = false;
        cur_pts.erase(cur_pts.find(d));
    } else {
        in_use[p.id] = true;
        cur_pts.insert(d);
        id_of[d] = p.id;
    }
}

void query() {
    if((int) cur_pts.size() == 0) {
        return;
    }
    int d = *(cur_pts.begin());
    is_ans[id_of[d]] = true;
}

void solve() {
    cin >> n;
    v.assign(n, house());
    for(int i = 0; i < n; i++) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
        v[i].id = i;
        pts.pb(point(v[i].x1, v[i].y2, i));
        pts.pb(point(v[i].x2, v[i].y1, i));
    }
    sort(pts.begin(), pts.end(), polarsort);
    /*for(point p : pts) {
        cout << p.x << " " << p.y << " " << p.id << "\n";
    }*/
    in_use.assign(n, false);
    is_ans.assign(n, false);
    for(int i = 0; i < (int) pts.size(); i++) {
        add_rem(pts[i]);
        if(i + 1 < (int) pts.size()) {
            if(direction(origo, pts[i], pts[i + 1])) {
                query();
            }
        }
    }
    for(int i = 0; i < n; i++) {
        if(is_ans[i]) {
            ans.pb(i);
        }
    }
    cout << (int) ans.size() << "\n";
    for(int x : ans) {
        cout << x + 1 << " ";
    }
    cout << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms1816 KiB
2Accepted21ms4740 KiB
subtask215/15
3Accepted1ms2220 KiB
4Accepted2ms2484 KiB
5Accepted7ms3724 KiB
6Accepted14ms5112 KiB
7Accepted16ms5496 KiB
subtask315/15
8Accepted1ms2948 KiB
9Accepted1ms2988 KiB
10Accepted2ms3012 KiB
11Accepted2ms3040 KiB
12Accepted3ms3280 KiB
subtask420/20
13Accepted2ms3280 KiB
14Accepted4ms3524 KiB
15Accepted8ms4916 KiB
16Accepted10ms5060 KiB
17Accepted12ms5268 KiB
subtask550/50
18Accepted28ms8932 KiB
19Accepted41ms11464 KiB
20Accepted68ms16200 KiB
21Accepted145ms28996 KiB
22Accepted137ms31840 KiB