Pagini recente » Cod sursa (job #1012386) | Cod sursa (job #45661) | Clasament simulare_oji_11_12_2 | Cod sursa (job #943123) | Cod sursa (job #810223)
Cod sursa(job #810223)
#include <cstdio>
#include <algorithm>
const int MAX_SIZE(3501);
int n;
struct box
{
int x;
int y;
int z;
} boxes [MAX_SIZE];
inline bool operator < (struct box a, struct box b)
{
return a.x < b.x;
}
int bit [MAX_SIZE] [MAX_SIZE];
inline void read (void)
{
for (int i(1) ; i <= n ; ++i)
std::scanf("%d%d%d",&boxes[i].x,&boxes[i].y,&boxes[i].z);
}
inline int lsb (int x)
{
return x & -x;
}
inline int query (int x, int y)
{
int i, j, max(0);
for (i = x ; i ; i -= lsb(i))
for (j = y ; j ; j -= lsb(j))
if (bit[i][j] > max)
max = bit[i][j];
return max;
}
inline void update (int x, int y, int length)
{
int i, j;
for (i = x ; i <= n ; i += lsb(i))
for (j = y ; j <= n ; j += lsb(j))
if (length > bit[i][j])
bit[i][j] = length;
}
inline int maximum_incresing_substring (void)
{
int max(0), length;
for (int i(1) ; i <= n ; ++i)
{
length = query(boxes[i].y - 1,boxes[i].z - 1) + 1;
update(boxes[i].y,boxes[i].z,length);
if (length > max)
max = length;
}
return max;
}
inline void clear_tree (void)
{
int x, y, z;
for (x = 1 ; x <= n ; ++x)
for (y = boxes[x].y; y <= n ; y += lsb(y))
for (z = boxes[x].z ; z <= n ; z += lsb(z))
bit[y][z] = 0;
}
int main (void)
{
std::freopen("cutii.in","r",stdin);
std::freopen("cutii.out","w",stdout);
int t;
std::scanf("%d%d",&n,&t);
while (t)
{
read();
std::sort(boxes + 1,boxes + n + 1);
std::printf("%d\n",maximum_incresing_substring());
clear_tree();
--t;
}
std::fclose(stdin);
std::fclose(stdout);
return 0;
}