Pagini recente » Cod sursa (job #2629388) | Cod sursa (job #1082309) | Cod sursa (job #1475059) | Cod sursa (job #2891232) | Cod sursa (job #1425602)
#include <cstdio>
#include <algorithm>
#define ub(x) (x&(-x))
#define boxx pair < int , pair < int , int > >
#define X first
#define Y second.first
#define Z second.second
using namespace std;
const int Nmax = 3510;
int n , T , i , crt , sol;
int aib[Nmax][Nmax];
boxx box[Nmax];
int query(boxx box)
{
int ans = 0;
for (int i = box.Y - 1; i ; i -= ub(i))
for (int j = box.Z - 1; j ; j -= ub(j))
ans = max(ans , aib[i][j]);
return ans + 1;
}
void update(boxx box , int val)
{
for (int i = box.Y; i <= n; i += ub(i))
for (int j = box.Z; j <= n; j += ub(j))
aib[i][j] = max(aib[i][j] , val);
}
void clearr(boxx box)
{
for (int i = box.Y; i <= n; i += ub(i))
for (int j = box.Z; j <= n; j += ub(j))
aib[i][j] = 0;
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
for (scanf("%d %d", &n, &T); T; --T)
{
for (i = 1; i <= n; ++i)
scanf("%d %d %d", &box[i].X , &box[i].Y , &box[i].Z);
sort(box + 1 , box + n + 1);
for (sol = 0 , i = 1; i <= n; ++i)
{
crt = query(box[i]);
sol = max(sol , crt);
update(box[i] , crt);
}
printf("%d\n", sol);
for (i = 1; i <= n; ++i)
clearr(box[i]);
}
return 0;
}