107512024-04-11 11:55:12EsVagyHázakcpp17Wrong answer 0/100173ms29952 KiB
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <queue>
#include <fstream>
#include <sstream>
#include <math.h>
#include <list>

using namespace std;

using ll = long long;

class vect
{
public:
    ll x;
    ll y;

    vect()
    {
    }

    vect(ll xCoord, ll yCoord) : x(xCoord), y(yCoord)
    {
    }

    vect operator+(vect a)
    {
        return vect(x + a.x, y + a.y);
    }

    vect operator-(vect a)
    {
        return vect(a.x - x, a.y - y);
    }

    int turn(vect a)
    {
        ll turn = x * a.y - a.x * y;
        if (turn == 0)
        {
            return 0;
        }
        return turn > 0 ? 1 : -1;
    }
};

bool between(ll a, ll b, ll c)
{
    return (a >= c && b <= c) || (b >= c && a <= c);
}

class segment
{
public:
    vect a;
    vect b;

    int turn(vect p)
    {
        vect v = b - a;
        vect w = p - a;
        return (v.turn(w));
    }

    bool contains(vect p)
    {
        return turn(p) == 0 && between(a.x, b.x, p.x) && between(a.y, b.y, p.y);
    }

    bool intercept(segment l)
    {
        int turnA = turn(l.a);
        int turnB = turn(l.b);
        int turnC = l.turn(a);
        int turnD = l.turn(b);

        if (turnA == 0 || turnB == 0 || turnC == 0 || turnD == 0)
        {
            return contains(l.a) || contains(l.b) || l.contains(a) || l.contains(b);
        }

        return (turnA != turnB) && (turnC != turnD);
    }
};

bool segment_compare(segment a, segment b) {
    return a.turn(b.a) < 0;
}

bool vect_compare(vect a, vect b) {
    int turn = a.turn(b);

    return turn == 1 || (turn == 0 && a.x + a.y < b.x + b.y);
}

struct point {
    vect v;
    ll segment_index;
    bool end;
};

bool point_compare(point a, point b) {
    return vect_compare(a.v, b.v);
}

struct indexedSegment {
    segment s;
    ll i;
    
    bool operator<(const indexedSegment& a) const {
        return segment_compare(this->s, a.s);
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll size;
    cin >> size;
    vector<segment> segments(size);
    vector<point> points(size * 2);
    for (ll i = 0; i < size; i++) {
        ll x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        vect s {x2, y1};
        vect e {x1, y2};
        segments[i] = segment {s, e};
        points[2*i] = point {s, i, false};
        points[2*i+1] = point {e, i, false};
    }
    
    sort(points.begin(), points.end(), point_compare);
    vector<ll> ans;
    set<indexedSegment> segset;
    for (point p : points) {
        if (!p.end) {
            segset.insert(indexedSegment {segments[p.segment_index], p.segment_index});
        }
        else {
            segset.erase(indexedSegment {segments[p.segment_index], p.segment_index});
        }
        if (ans.size() == 0 || ans[ans.size() - 1] != segset.begin()->i) {
            ans.push_back(p.segment_index);
        }
    }
    
    cout << ans.size() << "\n";
    for (ll i : ans) {
        cout << i << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1828 KiB
2Wrong answer17ms5428 KiB
subtask20/15
3Wrong answer3ms2244 KiB
4Wrong answer4ms2760 KiB
5Wrong answer8ms4140 KiB
6Wrong answer16ms5700 KiB
7Wrong answer17ms5700 KiB
subtask30/15
8Wrong answer3ms2820 KiB
9Wrong answer3ms2976 KiB
10Wrong answer3ms2948 KiB
11Wrong answer3ms2976 KiB
12Wrong answer4ms3192 KiB
subtask40/20
13Wrong answer4ms3248 KiB
14Wrong answer4ms3600 KiB
15Wrong answer9ms4392 KiB
16Wrong answer13ms4916 KiB
17Wrong answer13ms5192 KiB
subtask50/50
18Wrong answer28ms8236 KiB
19Wrong answer45ms10844 KiB
20Wrong answer78ms16044 KiB
21Wrong answer173ms29952 KiB
22Wrong answer172ms29904 KiB