Pagini recente » Cod sursa (job #3036717) | Cod sursa (job #2104410) | Cod sursa (job #1286536) | Cod sursa (job #2989625) | Cod sursa (job #953837)
Cod sursa(job #953837)
#include <cstdio>
#include <algorithm>
using namespace std;
struct box{
int x,y,z;
};
const int MAX_N = 3600;
int n;
box v[MAX_N];
short AIB[MAX_N][MAX_N];
inline int lsb(const int x)
{
return x & (-x);
}
inline int query(int x,int y)
{
short ret = 0;
int aux = y;
for(; x > 0 ; x-= lsb(x))
for(y = aux ; y > 0 ; y -= lsb(y))
ret = max(ret,AIB[x][y]);
return ret;
}
inline void update(int x,int y,short val)
{
int aux = y;
for(; x <= n ; x += lsb(x))
for(y = aux ; y <= n ; y += lsb(y)){
if(val)
AIB[x][y] = max(AIB[x][y],val);
else AIB[x][y] = 0;
}
}
bool comp(const box &a,const box &b)
{
return a.x == b.x ? ( a.y == b.y ? a.z < b.z : a.y < b.y ) : a.x < b.x;
}
void solve()
{
int i,x;
for(i = 1 ; i <= n ; ++ i)
scanf("%d %d %d",&v[i].x,&v[i].y,&v[i].z);
sort(v+1,v+i,comp);
for(i = 1 ; i <= n ; ++ i){
x = query(v[i].y-1,v[i].z-1);
update(v[i].y,v[i].z,x+1);
}
printf("%d\n",query(n,n));
for(i = 1 ; i <= n ; ++ i)
update(v[i].y,v[i].z,0);
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
int T;
scanf("%d %d",&n,&T);
while(T--)
solve();
return 0;
}