Cod sursa(job #1022277)

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

using namespace std;

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

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

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

inline 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)) {
			aib[i][j] = max(aib[i][j],val);
		}
	}
}

int main()
{
	cin>>n>>t;
	for(int i = 0;i < t;i++) {
		for(int j = 0;j < n;j++) {
			cin>>box[j].first>>box[j].second.first>>box[j].second.second;
		}
		sort(box,box + n);
		int ans = 1;
		for(int j = 0;j < n;j++) {
			int 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";
		for(int j = 0;j < n;j++) {
			update(box[j].second.first,box[j].second.second,0);
		}
	}
	return 0;
}