Pagini recente » Cod sursa (job #1817068) | Cod sursa (job #13621) | Istoria paginii lot-2017/baraj-1 | Cod sursa (job #963350) | Cod sursa (job #2037094)
#include <cstdio>
#include <cctype>
#include <algorithm>
#define MaxN 3500
#define DIM 10000
using namespace std;
char buff[DIM];
int poz;
FILE* fin = fopen("cutii.in","r");
FILE* fout = fopen("cutii.out","w");
struct abc{ int x,y,z; } v[MaxN+1];
int d[MaxN+1][MaxN+1];
int N;
bool cmp(const abc A, const abc B)
{
return A.x < B.x;
}
void Read(int& numar)
{
numar = 0;
while(!isdigit(buff[poz]))
if(++poz == DIM) fread(buff,1,DIM,fin),poz=0;
while(isdigit(buff[poz]))
{
numar = numar * 10 + buff[poz] - '0';
if(++poz == DIM) fread(buff,1,DIM,fin),poz=0;
}
}
void Update(int x, int y, int big)
{
for(int i = x; i <= N; i += i&-i)
for(int j = y; j <= N; j += j&-j)
d[i][j] = max(d[i][j], big);
}
void Free(int x, int y)
{
for(int i = x; i <= N; i += i&-i)
for(int j = y; j <= N; j += j&-j)
d[i][j] = 0;
}
int Query(int x, int y)
{
int res = 0;
for(int i = x; i > 0; i -= i&-i)
for(int j = y; j > 0; j -= j&-j)
res = max(res, d[i][j]);
return res;
}
int main(){
int i,j,best,now,T;
Read(N); Read(T);
while(T--)
{
for(i = 1; i <= N; ++i) Read(v[i].x), Read(v[i].y), Read(v[i].z);
sort(v+1,v+N+1,cmp);
best = 0;
for(i = 1; i <= N; ++i)
{
now = 1 + Query(v[i].y, v[i].z);
Update(v[i].y, v[i].z, now);
best = max(best, now);
}
for(i = 1; i <= N; ++i) Free(v[i].y, v[i].z);
fprintf(fout,"%d\n",best);
}
return 0;
}