Cod sursa(job #3252468)

Utilizator CaldareaCiprianCaldarea Ciprian CaldareaCiprian Data 29 octombrie 2024 18:38:36
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.71 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using TI = tuple<int, int, int>;
using VTI = vector<TI>;

int aib[3511][3511];
int NMAX = 3500;

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

void Update(int x, int y, int val)
{
    for (int i = x; i <= NMAX; i += i & -i)
        for (int j = y; j <= NMAX; j += j & -j)
            aib[x][y] = max(val, aib[i][j]);
}

int Query(int x, int y)
{
    int sum = 0;
    for (int i = x; i > 0; i -= i & -i)
        for (int j = y; j > 0; j -= j & -j)
            sum = max(aib[i][j], sum);
    return sum;
}

void Reset(int x, int y)
{
    for (int i = x; i <= NMAX; i += i & -i)
        for (int j = y; j <= NMAX; j += j & -j)
            aib[x][y] = 0;
}
int main()
{
    int currmax = 0;
    int a, b, c;
    int n, t;
    VTI v(n);
    int a1, a2, a3;
    int b1, b2, b3;
    int d;
    fin >> n >> t;
    while (t--)
    {


        for (int i = 0; i < n; ++i)
        {
            fin >> a >> b >> c;
            v[i] = {a, b, c};
        }

        sort(v.begin(), v.end(), [&a1, &a2, &a3, &b1, &b2, &b3](TI& a, TI& b)
             {
                 tie(a1, a2, a3) = a;
                 tie(b1, b2, b3) = b;
                 return a1 != b1 ? a1 < b1 : (a2 < b2);
             });

        currmax = 0;
        for (auto& [a, b, c] : v)
        {
            currmax = max(Query(b, c) + 1, currmax);
            Update(b + 1, c + 1, Query(b, c) + 1);
        }

        fout << currmax << '\n';

        for (auto [a, b, c] : v)
        {
            Reset(b + 1, c + 1);
        }
    }
}