Cod sursa(job #1457686)

Utilizator theprdvtheprdv theprdv Data 4 iulie 2015 03:43:53
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define zeros(x) ((x ^ (x - 1)) & x)
#define max(x, y)  (((x) > (y)) ? (x) : (y))

using namespace std;

struct point{
	int x, y, z;
} P[3501];

int N, T, AIB[3501][3501];

inline bool cmp(point a, point b){
	return a.z < b.z;
}

void Update(int px, int py, int val){
	for (; px <= N; px += zeros(px))
		for (int j = py; j <= N; j += zeros(j))
			AIB[px][j] = max(val, AIB[px][j]);
}

int Query(int px, int py){ // max
	int maxx = 0;

	for (; px; px -= zeros(px))
		for (int j = py; j; j -= zeros(j))
			maxx = max(maxx, AIB[px][j]);

	return maxx;
}

void Clear(int x, int y){
	for (; x <= N; x += zeros(x))
		for (int j = y; j <= N; j += zeros(j))
			AIB[x][j] = 0;
}

int main(){
	freopen("cutii.in", "r", stdin);
	freopen("cutii.out", "w", stdout);

	scanf("%d %d", &N, &T);

	for (; T; --T){
		for (int i = 1; i <= N; ++i)
			scanf("%d %d %d", &P[i].x, &P[i].y, &P[i].z);
		sort(P + 1, P + N + 1, cmp);

		for (int i = 1; i <= N; ++i)
			Update(P[i].x, P[i].y, Query(P[i].x - 1, P[i].y - 1) + 1);

		printf("%d\n", Query(N, N));

		for (int i = 1; i <= N; ++i)
			Clear(P[i].x, P[i].y);
	}

	return 0;
}