Mai intai trebuie sa te autentifici.

Cod sursa(job #743813)

Utilizator valentin.harsanValentin Harsan valentin.harsan Data 6 mai 2012 09:25:27
Problema Cutii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;

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

struct cutie {
	int x,y,z;
};

const int N = 3521;

int n,t,smax,aib[N][N];
cutie c[N];

inline bool cmp(const cutie &a, const cutie &b) {
	return a.x<b.x;
}

inline int max(const int &a, const int &b) {
	return a>b ? a : b;
}

inline int query(int i, int j) {
	int rez = 0, I = j;
	
	for(; i!=0; i -= i&(-i))
		for(j = I; j!=0; j -= j & (-j))
			rez = max(rez, aib[i][j]);
	
	return rez;
}

inline void update(int i, int j, const int &val) {
	int I = j;
	
	for(; i<=n; i += i&(-i))
		for(j = I; j<=n; j += j&(-j))
			aib[i][j] = max(aib[i][j], val);
}

inline void res(int i, int j) {
	int I = j;
	
	for(; i<=n; i += i&(-i))
		for(j = I; j<=n; j += j&(-j))
			aib[i][j] = 0;
}

int main() {
	int i,el;
	
	in >> n >> t;
	
	while(t--) {
		smax = 0;
		
		for(i = 1; i<=n; ++i)
			in >> c[i].x >> c[i].y >> c[i].z;
		
		sort(c + 1, c + n + 1, cmp);
		
		for(i = 1; i<=n; ++i) {
			
			el = query(c[i].y - 1, c[i].z - 1);
			
			if(el + 1 > smax)
				smax = el + 1;
			
			update(c[i].y, c[i].z, el + 1);
		}
		
		for(i = 1; i<=n; ++i)
			res(c[i].y, c[i].z);
		
		out << smax << "\n";
	}
	
	return 0;
}