Pagini recente » Cod sursa (job #2565684) | Cod sursa (job #2160076) | Cod sursa (job #1248595) | Cod sursa (job #3240891) | Cod sursa (job #1810039)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin ("cutii.in");
ofstream fout ("cutii.out");
#define MAX 3500
struct cutie
{
int nrs, x, y;
bool operator < (const cutie &c)const
{
return nrs < c.nrs;
}
};
vector<cutie> a;
int n, t, aib[MAX + 1][MAX + 1];
void update(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(val, aib[i][j]);
}
int query(int x, int y)
{
int rez = 0;
for (int i = x; i >= 1; i -= (i&-i))
for (int j = y; j >= 1; j -= (j & -j))
rez = max(rez, aib[i][j]);
return rez;
}
void clean(int x, int y)
{
for (int i = x; i <= n; i += (i&-i))
for (int j = y; j <= n; j += (j & -j))
aib[i][j] = 0;
}
void Solve()
{
int rez = 0;
for (int i = 1; i <= n; i++)fin >> a[i].nrs >> a[i].x >> a[i].y;
sort(a.begin(), a.end());
for (int i = 1; i <= n; i++)
{
int d = query(a[i].x, a[i].y);
update(a[i].x, a[i].y, d + 1);
rez = max(rez, d + 1);
}
for (int i = 1; i <= n; i++)clean(a[i].x, a[i].y);
fout << rez << '\n';
}
int main()
{
fin >> n >> t;
a.resize(n + 1);
for (int i = 1; i <= t; i++)Solve();
return 0;
}