Cod sursa(job #1539286)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 30 noiembrie 2015 17:17:07
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.96 kb
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define x first
#define y second
#define st first
#define nd second
#define pb push_back
#define nleft (n<<1)
#define nright (nleft+1)
#define lsb(a) (a&-a)
 
#include<vector>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<set>
#include<map>
#include<queue>
 
using namespace std;
#ifndef ONLINE_JUDGE
#include<fstream>
ifstream cin("cutii.in");
ofstream cout("cutii.out");
#else
#include<iostream>
#endif
 
const int NMAX = 3510;
const int sep = 200000;
const int INF = 0x3f3f3f3f;
const int dx[] = {0,0,-1,1}; //1,1,-1,1};
const int dy[] = {-1,1,0,0}; //1,-1,1,-1};
 
typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;
struct triple{
	int x,y,z;
};

triple A[NMAX];
int bit[NMAX][NMAX];

bool cmp(triple l, triple r)
{
	return l.z<r.z;
}

int query(int a, int b)
{
	int m=0;
	for(int x=a; x; x-=(x&(-x)))
		for(int y=b; y; y-=(y&(-y)))
		{
				m=max(m, bit[x][y]);
		}
	return m;
}

int update(int a, int b, int val)
{
	for(int x=a; x<=NMAX; x+=(x&(-x)))
		for(int y=b; y<=NMAX; y+=(y&(-y)))
		{
			bit[x][y]=max(val, bit[x][y]);
		}
}
 
int n,t;
int main()
{
	cin>>n;
	for(cin>>t; t; t--){
		memset(bit, 0, sizeof(bit[NMAX][NMAX]) * NMAX * NMAX);
		for(int i=1; i<=n; ++i)
		{
			cin>>A[i].x>>A[i].y>>A[i].z;
		}
		sort(A+1,A+n+1,cmp);
		
		for(int i=1; i<=n; ++i)
		{
			if(i==n)
				cout<<query(A[i].x-1, A[i].y-1) + 1<<"\n";
			else
				update(A[i].x, A[i].y, query(A[i].x-1, A[i].y-1) + 1);
		}
	}
}