107682024-04-11 15:36:07EsVagyHázakcpp17Wrong answer 30/100144ms23380 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-(const vect a) const
    {
        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(const vect p) const
    {
        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) {
    int turn = a.v.turn(b.v);
    if (turn != 0) {
        return turn == 1;
    }
    if (a.end != b.end) {
        return a.end < b.end;
    }
    return a.v.x + a.v.y < b.v.x + b.v.y;
}

struct indexedSegment {
    segment s;
    ll i;
    
    bool operator<(const indexedSegment a) const {
        //return segment_compare(this->s, a.s);
        int turn = this->s.turn(a.s.a);
        if (turn != 0) {
            return turn < 0;
        }
        return this->i < a.i;
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.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, true};
    }
    
    sort(points.begin(), points.end(), point_compare); 
    set<ll> ans;
    set<indexedSegment> segset;
    for (ll index = 0; index < points.size(); index++) {
        point p = points[index];
        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 (index < points.size() - 1 && p.v.turn(points[index + 1].v) == 0) {
            continue;
        }
        if (!segset.empty()) {
            ans.insert(segset.begin()->i);
        }
    }

    cout << ans.size() << "\n";
    for (ll i : ans) {
        cout << i + 1 << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted14ms3868 KiB
subtask215/15
3Accepted3ms2248 KiB
4Accepted4ms2700 KiB
5Accepted8ms3336 KiB
6Accepted16ms5156 KiB
7Accepted16ms5368 KiB
subtask315/15
8Accepted3ms3076 KiB
9Accepted3ms3448 KiB
10Accepted3ms3424 KiB
11Accepted3ms3692 KiB
12Accepted4ms3868 KiB
subtask40/20
13Accepted4ms3816 KiB
14Wrong answer4ms4172 KiB
15Accepted10ms5388 KiB
16Accepted12ms5344 KiB
17Accepted12ms5344 KiB
subtask50/50
18Wrong answer26ms7552 KiB
19Accepted43ms10668 KiB
20Accepted68ms13360 KiB
21Accepted143ms23380 KiB
22Wrong answer144ms22744 KiB