Cod sursa(job #2540618)

Utilizator FrostfireMagirescu Tudor Frostfire Data 7 februarie 2020 12:55:56
Problema Rays Scor 60
Compilator cpp-64 Status done
Runda irim_eralumis Marime 1.58 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define NMAX 200000

using namespace std;

ifstream f("rays.in");
ofstream g("rays.out");

int n, sol, val = 1;
struct punct
{   long long cx, cy;
    int nr, c;
};
unordered_map <int, int> umap;
vector <punct> v[5];
vector <pair <int, int> > a;

inline bool mycmp(punct a, punct b)
{   if(a.cy * b.cx < a.cx * b.cy || (a.cy * b.cx == a.cx * b.cy && a.c < b.c)) return 1;
    return 0;
}

void solve()
{   sort(v[1].begin(), v[1].end(), mycmp);
    a.clear();
    for(int i=0; i<v[1].size(); i++) a.push_back(make_pair(v[1][i].nr, v[1][i].c));

    for(int i=0; i<a.size(); i++)
        {   if(!a[i].second) umap[a[i].first] = val;
            else if(umap[a[i].first] == val)
                {   val++;
                    sol++;
                }
        }
}

int main()
{
    f >> n;
    for(int i=1; i<=n; i++)
        {   long long x, y1, y2;
            f >> x >> y1 >> y2;
            punct a1, a2;
            a1.cx = a2.cx = x;
            a1.cy = y1;
            a2.cy = y2;
            a1.nr = a2.nr = i;
            if(y1 < y2) a1.c = 0, a2.c = 1;
            else a1.c = 1, a2.c = 0;
            if(x > 0) v[1].push_back(a1), v[1].push_back(a2);
            else
                {   a1.cx = a2.cx = -x;
                    v[2].push_back(a1), v[2].push_back(a2);
                }
        }
    solve();
    v[1].clear();
    for(int i=0; i<v[2].size(); i++) v[1].push_back(v[2][i]);
    solve();
    g << sol << '\n';
    return 0;
}