Cod sursa(job #3364406)

Utilizator Mihai09Mihai Arteni Mihai09 Data 2 septembrie 2026 18:39:54
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <bits/stdc++.h>

using namespace std;

#define s second
#define f first
#define bit(i) (i & (-i))
typedef pair<int,pair<int,int>> point;

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

void pr(point x)
{
    fout <<x.first <<x.second.first <<x.second.second;
}

int t,n,a[3510][3510],ans;
point v[3500];

void update(pair<int,int>c, int nw)
{
    int x = c.f;
    int y = c.s;
    for(int i = x;i <= n;i+=bit(i))
    {
        for(int j = y;j <= n;j+=bit(j))
        {
            a[i][j] = max(a[i][j],nw);
        }
    }
    return;
}

int read(pair<int,int>c)
{
    int x = c.f;
    int y = c.s;
    int ans = 0;
    for(int i = x;i >= 1;i-=bit(i))
    {
        for(int j = y;j >= 1;j-=bit(j))
        {
            ans = max(ans,a[i][j]);
        }
    }
    return ans;
}

int main()
{
    fin >>n >>t;
    while(t--)
    {
        ans = 0;
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                a[i][j] = 0;
            }
        }
        for(int i = 1;i <= n;i++)
        {
            fin >>v[i].f >>v[i].s.f >> v[i].s.s;
        }
        sort(v+1,v+n+1);
        for(int i = 1;i <= n;i++)
        {
            update(v[i].s,read(v[i].s)+1);
            ans = max(ans,read(v[i].s));
        }
        fout <<ans<<"\n";
    }
    return 0;
}