Pagini recente » Cod sursa (job #2317603) | Istoria paginii runda/jc2018-runda-1 | Cod sursa (job #2407368) | Cod sursa (job #2186781) | Cod sursa (job #769636)
Cod sursa(job #769636)
#include<fstream>
#include<algorithm>
using namespace std;
int i,j,n,m,l[3501],t,max1,rez,p[3501],best[3501],poz,nr;
int x,y,z,a[3501],b[3501];
int compara(int i,int poz)
{
if(a[i]<a[poz]&&b[i]<b[poz])
return 1;
return 0;
}
int cauta(int poz)
{
int mij,st=0,dr=nr;
mij=(st+dr)/2;
while(st<=dr)
{
if(compara(mij,poz)&&!compara(mij+1,poz))
return mij;
else
if(compara(mij+1,poz))
st=mij+1,mij=(st+dr)/2;
else
dr=mij-1,mij=(st+dr)/2;
}
return nr;
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d%d",&n,&t);
while(t--)
{
for(i=1;i<=n;++i)
scanf("%d%d%d",&x,&y,&z),a[x]=y,b[x]=z;
nr=best[1]=l[1]=1;
l[0]=0;
rez=1;
for(i=2;i<=n;++i)
{
poz=cauta(i);
best[i]=poz+1;
p[i]=l[poz];
l[poz+1]=i;
if(nr<poz+1)
nr=poz+1;
if(rez<best[i])
rez=best[i];
}
printf("%d\n",rez);
}
return 0;
}