Pagini recente » Cod sursa (job #2376190) | Cod sursa (job #1748268) | Cod sursa (job #2736348) | Cod sursa (job #32231) | Cod sursa (job #999870)
Cod sursa(job #999870)
#include <cstdio>
#include <algorithm>
#define N 3501
#define zeros(x) (((x)^(x-1))&(x))
using namespace std;
int a[N][N];
struct nr
{
int x, y, z;
bool operator < (const nr &e) const
{
return x<e.x;
}
} b[N];
void update(int y, int z, int val)
{
while(y<=N)
{
while(z<=N)
{
a[y][z]=max(a[y][z], val);
z+=zeros(z);
}
y+=zeros(y);
}
}
int query(int y, int z)
{
int ret=0;
while(y)
{
while(z)
{
ret=max(a[y][z], ret);
z-=zeros(z);
}
y-=zeros(y);
}
return ret;
}
void clear(int y, int z)
{
while(y<=N)
{
while(z<=N)
{
a[y][z]=0;
z+=zeros(z);
}
y+=zeros(y);
}
}
int main()
{
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int n, t, i, dp, sol;
scanf("%d%d", &n, &t);
for(;t;t--)
{
for(i=1;i<=n;i++)
{
scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].z);
}
sort(b+1, b+n+1);
sol=0;
for(i=1;i<=n;i++)
{
dp=query(b[i].y-1, b[i].z-1)+1;
update(b[i].y, b[i].z, dp);
if(dp>sol) sol=dp;
}
for(i=1;i<=n;i++)
{
clear(b[i].y, b[i].z);
}
printf("%d\n", sol);
}
}