Pagini recente » Cod sursa (job #2955040) | Cod sursa (job #1650072) | Cod sursa (job #1215299) | Cod sursa (job #1570068) | Cod sursa (job #3253044)
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
struct Cutie
{
int x, y, z;
} C[3500 + 5];
int n, T, AIB[3505][3505];
bool fcmp(Cutie A, Cutie B)
{
return A.z < B.z;
}
void Add(int x, int y, int val)
{
for (int i = x; i <= n; i += i & -i)
for (int j = y; j <= n; j += j & -j)
AIB[i][j] = max(AIB[i][j], val);
}
int Query(int x, int y)
{
int S = 0;
for (int i = x; i; i -= i & -i)
for (int j = y; j; j -= j & -j)
S = max(AIB[i][j], S);
return S;
}
void Reinit(int x, int y)
{
for (int i = x; i <= n; i += i & -i)
for (int j = y; j <= n; j += j & -j)
AIB[x][y] = 0;
}
void Solve()
{
int nmax = -1;
for (int i = 1; i <= n; i ++)
fin >> C[i].x >> C[i].y >> C[i].z;
sort (C + 1, C + n + 1, fcmp);
for (int i = 1; i <= n; i ++)
{
int d = Query(C[i].x - 1, C[i].y - 1) + 1;
Add(C[i].x, C[i].y, d);
nmax = max(nmax, d);
}
for (int i = 1; i <= n; i ++)
Reinit(C[i].x, C[i].y);
fout << nmax << '\n';
}
int main()
{
fin >> n >> T;
while (T --)
Solve();
}