Cod sursa(job #1437093)

Utilizator vladrochianVlad Rochian vladrochian Data 16 mai 2015 20:59:36
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;

const int kMaxN = 3505;

ifstream fin("cutii.in");
ofstream fout("cutii.out");

struct Chestie {
	int x, y, z;
	bool operator<(const Chestie &other) const {
		return x < other.x;
	}
} a[kMaxN];

int N, sol;
int aib[kMaxN][kMaxN];

void UpdMax(int &a, int b) {
	if (b > a)
		a = b;
}

void Update(int x, int y, int val) {
	for (int i = x; i <= N; i += i & -i)
		for (int j = y; j <= N; j += j & -j)
			UpdMax(aib[i][j], val);
}

int Query(int x, int y) {
	int ans = 0;
	for (int i = x; i > 0; i -= i & -i)
		for (int j = y; j > 0; j -= j & -j)
			UpdMax(ans, aib[i][j]);
	return ans + 1;
}

void Test() {
	for (int i = 0; i < N; ++i)
		fin >> a[i].x >> a[i].y >> a[i].z;

	sort(a, a + N);

	memset(aib, 0, sizeof aib);
	sol = 0;
	for (int i = 0; i < N; ++i) {
		int crt = Query(a[i].y, a[i].z);
		UpdMax(sol, crt);
		Update(a[i].y, a[i].z, crt);
	}

	fout << sol << "\n";
}

int main() {
	int T;
	fin >> N >> T;
	while (T--)
		Test();
	return 0;
}