Pagini recente » Cod sursa (job #208289) | Cod sursa (job #1659237) | Cod sursa (job #2338172) | Cod sursa (job #1807607) | Cod sursa (job #1638107)
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAXN 3550
#define lsb(a) ((a) & (-(a)))
using namespace std;
struct cutie
{
int x, y, z;
cutie(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) { }
}a[MAXN];
//struct kdNod
//{
// kdNod *st, *dr, *parent;
// int key, domainx, domainy;
// kdNod(int dx, int dy, int key = 0)
// {
// st = dr = parent = NULL;
// this->key = key;
// domainx = dx;
// domainy = dy;
// }
//};
int n, t;
int AIB[MAXN][MAXN];
//kdNod* root = NULL;
//int cmpx(cutie e, cutie f) { return e.x < f.x; }
//int cmpy(cutie e, cutie f) { return e.y < f.y; }
int cmpz(cutie e, cutie f) { return e.z < f.z; }
//
//kdNod* buildTree(int st, int dr, int dir)
//{
// int auxi[MAXN];
// if (st > dr) return NULL;
// else if (st == dr) return new kdNod();
// else {
// cutie el = nth_element(a+st, a+dr+1, (dir == 1 ? cmpx : cmpy));
// }
//}
void citire()
{
for (int i = 1; i <= n; i++)
scanf("%d %d %d\n", &a[i].x, &a[i].y, &a[i].z);
sort(a+1, a+1+n, cmpz);
}
void add(cutie e, int val)
{
for (int i = e.x; i <= n; i += lsb(i))
for (int j = e.y; j <= n; j += lsb(j))
AIB[i][j] = val ? std::max(AIB[i][j], val) : 0;
}
int getMax(cutie e)
{
int rez = 0;
for (int i = e.x; i > 0; i -= lsb(i))
for (int j = e.y; j > 0; j -= lsb(j))
rez = std::max(rez, AIB[i][j]);
return rez;
}
void solve()
{
int rez = 1;
add(a[1], 1);
for (int i = 2; i <= n; i++) {
int best = getMax(a[i]);
add(a[i], best+1);
rez = std::max(rez, best+1);
}
printf("%d\n", rez);
}
int main()
{
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
scanf("%d %d", &n, &t);
while (t--) {
citire();
solve();
for (int i = 1; i <= n; i++)
add(a[i], 0);
}
return 0;
}