Pagini recente » Cod sursa (job #596598) | Monitorul de evaluare | Cod sursa (job #1001056) | Cod sursa (job #2893288) | Cod sursa (job #1294940)
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
using namespace std;
const int NMAX = 4000;
int T, N, Aib[NMAX][NMAX], Dp[NMAX];
pair<int, pair<int, int> > Box[NMAX];
int LSB(int X)
{
return (X & (X - 1)) ^ X;
}
void Update(int X, int Y, int Val)
{
for(int i = X; i <= N; i += LSB(i))
for(int j = Y; j <= N; j += LSB(j))
Aib[i][j] = max(Aib[i][j], Val);
}
int Query(int X, int Y)
{
int Ans = 0;
for(int i = X; i; i -= LSB(i))
for(int j = Y; j; j -= LSB(j))
Ans = max(Ans, Aib[i][j]);
return Ans;
}
const int MaxB = 8192;
char Buf[MaxB];
int Ptr;
inline int Get()
{
int Nr = 0;
while(!isdigit(Buf[Ptr]))
if(++ Ptr >= MaxB)
fread(Buf, 1, MaxB, stdin), Ptr = 0;
while(isdigit(Buf[Ptr]))
{
Nr = Nr * 10 + Buf[Ptr] - '0';
if(++Ptr >= MaxB)
fread(Buf, 1, MaxB, stdin), Ptr = 0;
}
return Nr;
}
int main()
{
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
fread(Buf, 1, MaxB, stdin);
N = Get();
T = Get();
for(; T; T --)
{
for(int i = 1; i <= N; ++ i)
for(int j = 1; j <= N; ++ j)
Aib[i][j] = 0;
for(int i = 1; i <= N; ++ i)
Dp[i] = 0;
for(int i = 1; i <= N; ++ i)
{
Box[i].first = Get();
Box[i].second.first = Get();
Box[i].second.second = Get();
}
sort(Box + 1, Box + N + 1);
for(int i = 1; i <= N; ++ i)
{
Dp[i] = 1 + Query(Box[i].second.first, Box[i].second.second);
Update(Box[i].second.first, Box[i].second.second, Dp[i]);
}
int Ans = 0;
for(int i = 1; i <= N; ++ i) Ans = max(Ans, Dp[i]);
printf("%i\n", Ans);
}
}