Pagini recente » Cod sursa (job #1853426) | Cod sursa (job #1499406) | Cod sursa (job #1324291) | Cod sursa (job #92190) | Cod sursa (job #976343)
Cod sursa(job #976343)
#include <fstream>
#include <algorithm>
#define In "cutii.in"
#define Out "cutii.out"
#define Nmax 3502
#define PII pair<int ,pair<int ,int > >
using namespace std;
PII A[Nmax];
int N, F[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])
aib[i][j] = max(aib[i][j],value);
}
inline void Init(const int x,const int y)
{
int i,j;
for(i = x;i <= N;i += F[x])
for(j = y;j <= N;j += F[y])
aib[i][j] = 0;
}
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])
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);
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);
}
for(i = 1;i <= N; ++i)
AIB.Init(A[i].second.first,A[i].second.second);
return best;
}
inline void Calculate()
{
int i;
for(i=1;i<=N;++i)
F[i] = (i& -i);
}
int main()
{
int T;
in>> N >> T;
for(Calculate(); T ;--T)
{
Read();
out<<Solve()<<"\n";
}
in.close();
out.close();
return 0;
}