Cod sursa(job #1425602)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 27 aprilie 2015 19:32:01
Problema Cutii Scor 100
Compilator cpp Status done
Runda pregatire-lot-aib Marime 1.37 kb
#include <cstdio>
#include <algorithm>

#define ub(x) (x&(-x))

#define boxx pair < int , pair < int , int > >
#define X first
#define Y second.first
#define Z second.second

using namespace std;

const int Nmax = 3510;

int n , T , i , crt , sol;
int aib[Nmax][Nmax];

boxx box[Nmax];

int query(boxx box)
{
    int ans = 0;

    for (int i = box.Y - 1; i ; i -= ub(i))
     for (int j = box.Z - 1; j ; j -= ub(j))
      ans = max(ans , aib[i][j]);

    return ans + 1;
}

void update(boxx box , int val)
{
    for (int i = box.Y; i <= n; i += ub(i))
     for (int j = box.Z; j <= n; j += ub(j))
      aib[i][j] = max(aib[i][j] , val);
}

void clearr(boxx box)
{
    for (int i = box.Y; i <= n; i += ub(i))
     for (int j = box.Z; j <= n; j += ub(j))
      aib[i][j] = 0;
}

int main()
{
    freopen("cutii.in","r",stdin);
    freopen("cutii.out","w",stdout);

    for (scanf("%d %d", &n, &T); T; --T)
    {
        for (i = 1; i <= n; ++i)
            scanf("%d %d %d", &box[i].X , &box[i].Y , &box[i].Z);

        sort(box + 1 , box + n + 1);

        for (sol = 0 , i = 1; i <= n; ++i)
        {
            crt = query(box[i]);

            sol = max(sol , crt);

            update(box[i] , crt);
        }

        printf("%d\n", sol);

        for (i = 1; i <= n; ++i)
            clearr(box[i]);
    }

    return 0;
}