Pagini recente » Cod sursa (job #1968794) | Cod sursa (job #2763995) | Cod sursa (job #1843118) | Cod sursa (job #1826651) | Cod sursa (job #976330)
Cod sursa(job #976330)
#include <fstream>
#include <algorithm>
#define In "cutii.in"
#define Out "cutii.out"
#define Nmax 3502
#define f(x) (x &(-(x)))
#define PII pair<int ,pair<int ,int > >
using namespace std;
PII A[Nmax];
int N, cnt, mat[Nmax][Nmax];
ifstream in(In);
ofstream out(Out);
class AIB2D
{
public:
inline void Update(const int x,const int y,const int value)
{
int i,j;
for(i = x;i <= N;i += f(x))
for(j = y;j <= N;j += f(y))
{
if(mat[i][j]!=cnt)
{
aib[i][j] = value;
mat[i][j] = cnt;
}
else
aib[i][j] = max(aib[i][j],value);
}
}
inline int Query(const int x,const int y)
{
int i, j, value = 0;
for(i = x; i; i -= f(i))
for(j = y; j;j -= f(j))
if(mat[i][j]==cnt)
value = max(aib[i][j],value);
return value;
}
private: int aib[Nmax][Nmax];
};
AIB2D AIB;
inline void Read()
{
for(int i=1;i<=N;++i)
in>>A[i].first>>A[i].second.first>>A[i].second.second;
}
inline int Solve()
{
int i,best = 0, x;
sort(A+1,A+N+1);
++cnt;
for(i = 1;i <= N; ++i)
{
x = 1+AIB.Query(A[i].second.first,A[i].second.second);
AIB.Update(A[i].second.first,A[i].second.second,x);
best = max(best,x);
}
return best;
}
int main()
{
int T;
for(in>> N >> T; T ;--T)
{
Read();
out<<Solve()<<"\n";
}
in.close();
out.close();
return 0;
}