Cod sursa(job #1022275)

Utilizator ELHoriaHoria Cretescu ELHoria Data 5 noiembrie 2013 01:21:50
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;

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

const short nmax = 3505;
short n, t;
pair<short,pair<short,short> >  box[nmax];
short aib[nmax][nmax];

inline short query(short x,short y) {
	short ret = 0;
	for(short i = x;i > 0;i -= (i & -i)) {
		for(short j = y;j > 0;j -= (j & -j)) {
			ret = max(ret,aib[i][j]);
		}
	}
	return ret;
}

inline void update(short x,short y,short val) {
	for(short i = x;i <= n;i += (i & -i)) {
		for(short j = y;j <= n;j += (j & -j)) {
			aib[i][j] = max(aib[i][j],val);
		}
	}
}

int main()
{
	cin>>n>>t;
	for(short i = 0;i < t;i++) {
		if(i) memset(aib,0,sizeof(aib));
		for(short j = 0;j < n;j++) {
			cin>>box[j].first>>box[j].second.first>>box[j].second.second;
		}
		sort(box,box + n,[] (const pair<short,pair<short,short> > &a,const pair<short,pair<short,short> > &b ) {
			return a.first < b.first;
		});
		short ans = 1;
		for(short j = 0;j < n;j++) {
			short val = 1 + query(box[j].second.first - 1,box[j].second.second - 1);
			ans = max(ans,val);
			update(box[j].second.first,box[j].second.second,val);
		}
		cout<<ans<<"\n";
	}
	return 0;
}