Pagini recente » Cod sursa (job #2323997) | Cod sursa (job #898317) | Cod sursa (job #3166970) | Cod sursa (job #1290862) | Cod sursa (job #1409590)
#include<cstdio>
#include<cstring>
int max2(int a,int b){
if(a>b)
return a;
return b;
}
const int N=3500;
class Box{
public:
int x,y,z;
};
int aib[N+1][N+1];
Box v[N+1];
int n,t;
int d[N+1];
int query(int x,int y){
int r=0;
int cy=y;
while(x){
y=cy;
while(y){
if(d[aib[x][y]]>d[r])
r=aib[x][y];
y-=y&(-y);
}
x-=x&(-x);
}
return r;
}
void update(int x,int y,int val){
int cy=y;
while(x<=n){
y=cy;
while(y<=n){
if(d[aib[x][y]]<d[val])
aib[x][y]=val;
y+=y&(-y);
}
x+=x&(-x);
}
}
#define BUF_SIZE 4096
char buf[BUF_SIZE];
int pos = BUF_SIZE;
inline char getChar(FILE *f) {
if (pos == BUF_SIZE) {
fread(buf, 1, BUF_SIZE, f);
pos = 0;
}
return buf[pos++];
}
bool isdigit(char c){
return '0'<=c&&c<='9';
}
inline int readInt(FILE *f) {
int result = 0;
char c;
do {
c = getChar(f);
} while (!isdigit(c));
do {
result = 10 * result + c - '0';
c = getChar(f);
} while (isdigit(c));
return result;
}
int main(){
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d%d",&n,&t);
while(t--){
for(int i=1;i<=n;i++){
v[i].x=readInt(stdin);
v[v[i].x].y=readInt(stdin);
v[v[i].x].z=readInt(stdin);
}
memset(aib,0,sizeof(aib));
memset(d,0,sizeof(d));
int res=0;
for(int i=1;i<=n;i++){
d[i]=d[query(v[i].y,v[i].z)]+1;
res=max2(res,d[i]);
update(v[i].y,v[i].z,i);
}
printf("%d\n",res);
}
return 0;
}