Pagini recente » Cod sursa (job #1273882) | Cod sursa (job #372) | Cod sursa (job #491121) | Cod sursa (job #1022978) | Cod sursa (job #1093635)
#include <cstdio>
#include <cstring>
#include <algorithm>
int n,t;
const int Q=3500;
struct cutie{
int x,y,z;
} v[Q+1];
bool scm(cutie a, cutie b)
{
return a.x < b.x;
}
int arb[Q+1],bigz[Q+1],bigy[Q+1];
int ask(int p)
{
int p0=p+1;
int rez=1;
while(p)
{
if(rez< arb[p]+1 && bigz[p]<v[p0].z && bigy[p]<v[p0].y)
rez=arb[p]+1;
p-=p&(-p);
}
return rez;
}
void update(int p, int val)
{
int init=p;
while(p<=n)
{
if(arb[p]<val)
{
arb[p]=val;
bigz[p]=v[init].z;
bigy[p]=v[init].y;
}
p+=p&(-p);
}
}
void solve()
{
for(int i=1; i<=n; i++)
{
scanf("%d%d%d",&v[i].x, &v[i].y, &v[i].z);
}
std:: sort(v+1,v+n+1,scm);
memset(arb,0, sizeof arb);
int val,max=0;
for(int i=1; i<=n; i++)
{
val=ask(i-1);
if(val>max)
max=val;
update(i,val);
}
printf("%d\n",max);
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d%d",&n,&t);
for(int f=1; f<=t; f++)
{
solve();
}
return 0;
}