Pagini recente » Profil Saitama | Cod sursa (job #2363914) | Cod sursa (job #1217097) | Cod sursa (job #138431) | Cod sursa (job #2078920)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
FILE *in = fopen("cutii.in","r");
FILE *out = fopen("cutii.out","w");
int n,t,aib[3505][3505];
pair<int,pair<int,int>> v[3505];
void update(int px,int py,int val)
{
while(px<=n)
{
while(py<=n)
{
aib[px][py] = max(aib[px][py],val);
py += py&(-py);
}
px += px&(-px);
}
}
int query(int px,int py)
{
int ma=0;
while(px>0)
{
while(py>0)
{
ma=max(ma,aib[px][py]);
py -= py &(-py);
}
px -= px & (-px);
}
return ma;
}
void clearr(int px,int py)
{
while(px<=n)
{
while(py<=n)
{
aib[px][py] = 0;
py += py&(-py);
}
px += px&(-px);
}
}
int main()
{
fscanf(in,"%d%d",&n,&t);
while(t)
{
int ans=0;
for(int i=1;i<=n;i++)
{
int x ,y,z;
fscanf(in,"%d%d%d",&x,&y,&z);
v[i].first=x;
v[i].second.first=y;
v[i].second.second=z;
}
sort(v+1,v+n+1);
for(int i=1;i<=n;i++)
{
int sol=query(v[i].second.first-1,v[i].second.second-1)+1;
ans=max(sol,ans);
update(v[i].second.first,v[i].second.second,sol);
}
fprintf(out,"%d\n",ans);
for(int i=1;i<=n;i++)
clearr(v[i].second.first,v[i].second.second);
t--;
}
return 0;
}