Pagini recente » Cod sursa (job #133371) | Cod sursa (job #1045024) | Cod sursa (job #581353) | Cod sursa (job #312047) | Cod sursa (job #734749)
Cod sursa(job #734749)
#include <stdio.h>
#include <algorithm>
#define LMAX 3600
using namespace std;
struct box
{
int x, y, z;
} x[LMAX];
int zero[LMAX], AIB[LMAX][LMAX];
inline bool comp (box A, box B)
{
return A.z < B.z;
}
void set (int x0, int y0, int N)
{
int i, j;
for (i = x0; i <= N; i = i + zero[i])
for (j = y0; j <= N; j = j + zero[j])
AIB[i][j] = 0;
}
int Query (int x0, int y0)
{
int i, j, best = 0;
for (i = x0; i >= 1; i = i - zero[i])
for (j = y0; j >= 1; j = j - zero[j])
if (AIB[i][j] > best)
best = AIB[i][j];
return best;
}
void Upgrade (int x0, int y0, int val, int N)
{
int i, j;
for (i = x0; i <= N; i = i + zero[i])
for (j = y0; j <= N; j = j + zero[j])
if (AIB[i][j] < val)
AIB[i][j] = val;
}
int main ()
{
int N, i, pw = 0, Q, ans, now;
freopen ("cutii.in", "r", stdin);
freopen ("cutii.out", "w", stdout);
scanf ("%d%d", &N, &Q);
zero[1] = 1;
for (i = 2; i <= N; i ++)
if (i == (1 << (pw + 1)))
zero[i] = i, pw ++;
else
zero[i] = zero[i - (1 << pw)];
while (Q --)
{
for (i = 1; i <= N; i ++)
scanf ("%d%d%d", &x[i].x, &x[i].y, &x[i].z);
sort (x + 1, x + N + 1, comp);
ans = 0;
for (i = 1; i <= N; i ++)
{
now = Query (x[i].x, x[i].y) + 1;
if (now > ans)
ans = now;
Upgrade (x[i].x, x[i].y, now, N);
}
printf ("%d\n", ans);
for (i = 1; i <= N; i ++)
set (x[i].x, x[i].y, N);
}
return 0;
}