Cod sursa(job #931668)
#include<fstream>
#include<algorithm>
using namespace std;
int t,n,i,j,maxim,l[3501],p[3501],best[3501],nr,poz;
struct cutie
{
int l,L,h;
};
cutie a[3501];
int cmp(cutie a,cutie b)
{
return ((a.l<b.l)||(a.l==b.l&&a.L<b.L)||(a.l==b.l&&a.L==b.L&&a.h<b.h));
}
int comp(cutie a, cutie b)
{
if(a.l>=b.l||a.L>=b.L||a.h>=b.h)
return 0;
return 1;
}
int comp1(cutie a, cutie b)
{
if(a.l<=b.l&&a.L<=b.L&&a.h<=b.h)
return 1;
return 0;
}
int cauta(cutie x)
{
int st,dr,m;
st=0,dr=nr;
m=(st+dr)/2;
while(st<=dr)
{
if(comp(a[l[m]],x)&&comp1(a[l[m+1]],x)==0)
return m;
else
if(comp(a[l[m]],x))
st=m+1, m=(st+dr)/2;
else
dr=m-1, m=(st+dr)/2;
}
return nr;
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d%d",&n,&t);
while(t)
{
--t;
maxim=0;
for(i=1;i<=n;++i)
{
scanf("%d%d%d",&a[i].l,&a[i].L,&a[i].h);
l[i]=best[i]=0;
}
sort(a+1,a+n+1,cmp);
l[1]=best[1]=nr=1;
for(i=2;i<=n;++i)
{
poz=cauta(a[i]);
best[i]=poz+1;
if(l[poz+1]==0)
l[poz+1]=i;
if(poz+1>nr)
nr=poz+1;
if(poz+1>maxim)
maxim=poz+1;
}
printf("%d\n",maxim);
//for(i=1;i<=n;++i)
// printf("%d ",l[i]);
}
return 0;
}