Cod sursa(job #463789)

Utilizator darrenRares Buhai darren Data 17 iunie 2010 14:58:00
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include<fstream>
#include<algorithm>
using namespace std;

struct point
{
	int x, y, z;
};
bool cmp(point a, point b)
{
	return a.z <= b.z;
}

void update(int p1, int p2, int val);
int query(int p1, int p2);
int n, t, aib[3501][3501], i;
point p[3501];

int main()
{
	ifstream fin("cutii.in");
	ofstream fout("cutii.out");
	fin >> n >> t;
	
	for (i = 1; i <= t; ++i)
	{
		int mx = 0;
		for (int j = 1; j <= n; ++j)
			fin >> p[j].x >> p[j].y >> p[j].z;
		sort(p + 1, p + n + 1, cmp);
		for (int j = 1; j <= n; ++j)
		{
			int x = query(p[j].x, p[j].y);
			update(p[j].x, p[j].y, x + 1);
			if (x + 1 > mx)
				mx = x + 1;
		}
		fout << mx << '\n';
	}
}

void update(int p1, int p2, int val)
{
	for (; p1 <= n; p1 += p1 & -p1)
	{
		int aux = p2;
		for (; aux <= n; aux += aux & -aux)
			if (val > aib[p1][aux])
				aib[p1][aux] = val;
	}
}

int query(int p1, int p2)
{
	int mx = 0;
	for (; p1 >= 1; p1 -= p1 & -p1)
	{
		int aux = p2;
		for (; aux >= 1; aux -= aux & -aux)
			if (aib[p1][aux] > mx)
				mx = aib[p1][aux];
	}
	return  mx;
}