Pagini recente » Cod sursa (job #627162) | Cod sursa (job #795272) | Cod sursa (job #2233227) | Cod sursa (job #2042359) | Cod sursa (job #2328250)
#include <fstream>
#include <algorithm>
#define nmax 3500
using namespace std;
ifstream f("cutii.in");
ofstream g("cutii.out");
int n,t,p[nmax],len;
struct s1
{
int a,b,c;
} c[nmax];
struct s2
{
int x,y;
} q[nmax];
bool cmp (s1 x, s1 y)
{
return x.a>y.a;
}
int getpos (int u,int v)
{
int low=1,hi=len;
while (low<hi)
{
int mid=(low+hi)/2;
if (q[mid].x>u && q[mid].y>v) low=mid+1;
else hi=mid;
}
if (q[low].x<=u && q[low].y<=v && q[low-1].x>u && q[low-1].y>v) return low;
return -1;
}
int sdmax (void)
{
len=0;
for (int i=1;i<=n;i++) q[i].x=q[i].y=p[i]=0;
for (int i=1;i<=n;i++)
{
int pos=getpos(c[i].b,c[i].c);
if (pos==-1)
{
len++;
q[len].x=c[i].b;
q[len].y=c[i].c;
p[i]=len;
}
else
{
q[pos].x=c[i].b;
q[pos].y=c[i].c;
}
}
return len;
}
int main()
{
f>>n>>t;
while (t--)
{
for (int i=1;i<=n;i++) f>>c[i].a>>c[i].b>>c[i].c;
sort(c+1,c+n+1,cmp);
g<<sdmax()<<'\n';
}
f.close();
g.close();
return 0;
}