Pagini recente » Cod sursa (job #568906) | Cod sursa (job #1000638) | Cod sursa (job #1647292) | Cod sursa (job #1498228) | Cod sursa (job #424400)
Cod sursa(job #424400)
#include <cstdio>
#include <algorithm>
using namespace std;
#define nmax 3510
struct cutie
{
int x, y, z;
} v[nmax];
int n, a[nmax][nmax], t, sol;
int cmp(cutie a, cutie b)
{
return a.x<b.x;
}
int query(int x, int y)
{
/*int r=0, j;
do
{
j=y;
do
{
r=max(r,a[x][j]);
j=j&(j-1);
}
while (j);
x=x&(x-1);
}
while (x);
return r;*/
int c=y, r=0;
for (; x>0; x-=(x^(x-1))&x)
for (y=c; y>0; y-=(y^(y-1))&y)
r=max(r,a[x][y]);
return r;
}
void update(int x, int y, int val)
{
int c=y;
for (; x<=n; x+=(x&(x-1))^x)
for (y=c; y<=n; y+=(y&(y-1))^y)
a[x][y]=max(a[x][y],val);
}
void update2(int x, int y)
{
int c=y;
for (; x<=n; x+=(x&(x-1))^x)
for (y=c; y<=n; y+=(y&(y-1))^y)
a[x][y]=0;
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d %d",&n,&t);
int i, c, j;
while (t--)
{
for (i=1; i<=n; i++) scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].z);
sort(v+1,v+n+1,cmp);
sol=0;
for (i=1; i<=n; i++)
{
c=query(v[i].y-1,v[i].z-1)+1;
sol=max(sol, c);
update(v[i].y,v[i].z, c);
}
for (i=1; i<=n; i++) update2(v[i].y,v[i].z);
printf("%d\n",sol);
}
}