Pagini recente » Cod sursa (job #3146832) | Cod sursa (job #2532081) | Cod sursa (job #928243) | Cod sursa (job #2656133) | Cod sursa (job #2062477)
#include <bits/stdc++.h>
#define UB(x) x&(-x)
using namespace std;
int n,t,i,aib[3510][3510],sol,ans;
pair<int,pair<int,int> >v[3510];
int query(int x,int y)
{
int ma=0;
for(int i=x; i<=n; i+=UB(i))
for(int j=y; j<=n; j+=UB(j))
ma=max(ma,aib[i][j]);
return ma;
}
void update(int x,int y,int va)
{
for(int i=x; i; i-=UB(i))
for(int j=y; j; j-=UB(j))
aib[i][j]=max(aib[i][j],va);
}
void neww(int x,int y)
{
for(int i=x; i; i-=UB(i))
for(int j=y; j; j-=UB(j))
aib[i][j]=0;
}
int main()
{
ifstream f ("cutii.in");
ofstream g ("cutii.out");
f>>n>>t;
while(t--)
{
for(i=1; i<=n; ++i)
f>>v[i].first>>v[i].second.first>>v[i].second.second;
sort(v+1,v+n+1);
ans=0;
for(i=n; i>=1; --i)
{
sol=query(v[i].second.first+1,v[i].second.second+1)+1;
ans=max(ans,sol);
update(v[i].second.first,v[i].second.second,sol);
}
g<<ans<<'\n';
for(i=n; i>=1; --i)
neww(v[i].second.first,v[i].second.second);
}
return 0;
}