Cod sursa(job #2601038)

Utilizator r00t_Roman Remus r00t_ Data 13 aprilie 2020 16:54:25
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.36 kb
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <string>
#include <queue>
#include <unordered_set>
#include <set>

using namespace std;

ifstream fin("cutii.in");
ofstream fout("cutii.out");

int t, n;
int ct[10000], rez[10000];
vector<tuple<int, int, int>>tp;

bool bigger(tuple<int, int, int>& lhs, tuple<int, int, int>& rhs)
{
    int x, y, z, a, b, c;
    tie(x, y, z) = lhs;
    tie(a, b, c) = rhs;
    if (x > a&& y > b&& z > c)
        return true;
    return false;
}

void addBox(int x)
{
    int root = x;
    while (root != ct[root])
    {
        root = ct[root];
    }
    rez[root]++;

    while (x != ct[x])
    {
        int aux = ct[x];
        ct[x] = root;
        x = aux;
    }


}

void solve(int lhs, int rhs)
{
    if (lhs == rhs)
        return;
    else
    {
        int mid = (lhs + rhs) / 2;
        for (int i = mid+1; i <= rhs; i++)
        {
            if (bigger(tp[i - 1], tp[i]))
                ct[i] = ct[i-1];
        }
        if (rhs + 1 < n && bigger(tp[rhs],tp[rhs+1]))
        {
            ct[rhs + 1] = rhs;
        }
        solve(lhs, mid);
        solve(mid + 1, rhs);

    }


}

int main()
{
    
    fin >> n >> t;
    for (int k = 0; k < t; k++)
    {
        for (int i = 0; i < n; i++) {
            int x, y, z;
            fin >> x >> y >> z;
            tp.push_back({ x,y,z });
            ct[i] = i;
        }


        sort(tp.begin(), tp.end(), [](tuple<int, int, int>& lhs, tuple<int, int, int>& rhs)
        {
            if (get<0>(lhs) > get<0>(rhs))
            {
                if (get<1>(lhs) > get<1>(rhs))
                {
                    if (get<2>(lhs) > get<2>(rhs))
                    {
                        return get<2>(lhs) > get<2>(rhs);
                    }
                    return get<1>(lhs) > get<1>(rhs);
                }
                return get<0>(lhs) > get<0>(rhs);
            }

            return (get<0>(lhs) > get<0>(rhs));
        });

        int sol = 0;
        solve(0, n - 1);

        for (int i = 0; i < n; i++)
            addBox(i);
        



        for (int i = 0; i < n; i++) {
            sol = max(sol, rez[i]);
            rez[i] = 0;
        }
        fout << sol<<'\n';

        tp.clear();
    }

    



}