Cod sursa(job #2263199)

Utilizator memecoinMeme Coin memecoin Data 18 octombrie 2018 13:02:05
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h>

#define MAXN 3501

using namespace std;

int n;

struct Box {
	int x, y, z;

	bool operator<(Box &rhs) {
		return z < rhs.z;
	}
};

Box boxes[MAXN];

int aib[MAXN][MAXN];

int lsb(int x) {
	return x & -x;
}

int query(int x, int y) {
	int result = 0;

	while (x > 0) {
		int ty = y;
		while (ty > 0) {
			result = max(result, aib[x][ty]);
			ty -= lsb(ty);
		}

		x -= lsb(x);
	}

	return result;
}

void update(int x, int y, int value) {
	while (x <= n) {
		int ty = y;
		while (ty <= n) {
			aib[x][ty] = max(aib[x][ty], value);
			ty += lsb(ty);
		}

		x += lsb(x);
	}
}

void reset(int x, int y) {
	while (x <= n) {
		int ty = y;
		while (ty <= n) {
			aib[x][ty] = 0;
			ty += lsb(ty);
		}

		x += lsb(x);
	}
}

void solve() {
	int x, y, z;

	for (int i = 1; i <= n; ++i) {
		scanf("%d %d %d", &x, &y, &z);
		boxes[i] = { x,y,z };
	}

	sort(boxes + 1, boxes + n + 1);

	int gbest = 0;

	for (int i = 1; i <= n; ++i) {
		int q = query(boxes[i].x, boxes[i].y);
		update(boxes[i].x, boxes[i].y, q + 1);
		gbest = max(q + 1, gbest);
	}

	printf("%d\n", gbest);
}

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

	int t;
	scanf("%d %d", &n, &t);

	for (int i = 0; i < t; ++i) {
		solve();
	}

	return 0;
}