Pagini recente » Cod sursa (job #2715234) | Cod sursa (job #685435) | Cod sursa (job #600725) | Cod sursa (job #685434) | Cod sursa (job #600712)
Cod sursa(job #600712)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 3505
int X[MAXN], Y[MAXN], Z[MAXN], A[MAXN][MAXN], N, I[MAXN];
struct cmp {
bool operator()(const int &a, const int &b)const{
return Z[a]<Z[b];
}
};
inline int lbit(int x){
return (x^(x-1) & x);
}
int Query(int x, int y){
int r=0;
for( ; x; x-=lbit(x))
for( ; y; y-=lbit(y))
r=max(r, A[x][y]);
return r;
}
void Update(int x, int y, int v){
for( ; x<=N; x+=lbit(x))
for( ; y<=N; y+=lbit(y))
if(v == 0)
A[x][y]=0;
else
A[x][y]=max(A[x][y], v);
}
int main(){
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int T, i, r, aux;
scanf("%d%d", &N, &T);
while(T--){
for(i=1; i<=N; i++){
scanf("%d%d%d", X+i, Y+i, Z+i);
I[i]=i;
}
sort(I+1, I+N+1, cmp());
r=0;
for(i=1; i<=N; i++){
aux=Query(X[I[i]]-1, Y[I[i]]-1)+1;
Update(X[I[i]], Y[I[i]], aux);
r=max(r, aux);
}
for(i=1; i<=N; i++)
Update(X[I[i]], Y[X[i]], 0);
printf("%d\n", r);
}
return 0;
}