1292 2022. 03. 30 15:34:44 Valaki2 Házak cpp14 Elfogadva 100/100 145ms 31840 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;
}
Részfeladat Összpont Teszt Verdikt Idő Memória
subtask1 0/0
1 Elfogadva 2ms 1816 KiB
2 Elfogadva 21ms 4740 KiB
subtask2 15/15
3 Elfogadva 1ms 2220 KiB
4 Elfogadva 2ms 2484 KiB
5 Elfogadva 7ms 3724 KiB
6 Elfogadva 14ms 5112 KiB
7 Elfogadva 16ms 5496 KiB
subtask3 15/15
8 Elfogadva 1ms 2948 KiB
9 Elfogadva 1ms 2988 KiB
10 Elfogadva 2ms 3012 KiB
11 Elfogadva 2ms 3040 KiB
12 Elfogadva 3ms 3280 KiB
subtask4 20/20
13 Elfogadva 2ms 3280 KiB
14 Elfogadva 4ms 3524 KiB
15 Elfogadva 8ms 4916 KiB
16 Elfogadva 10ms 5060 KiB
17 Elfogadva 12ms 5268 KiB
subtask5 50/50
18 Elfogadva 28ms 8932 KiB
19 Elfogadva 41ms 11464 KiB
20 Elfogadva 68ms 16200 KiB
21 Elfogadva 145ms 28996 KiB
22 Elfogadva 137ms 31840 KiB