Pagini recente » Cod sursa (job #2842802) | Cod sursa (job #3133399) | Cod sursa (job #2930899) | Cod sursa (job #2569568) | Cod sursa (job #2153264)
#include <algorithm>
#include <fstream>
using namespace std;
const int DIM = 3510;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
struct box
{
int x, y, z;
box()
{
x = y = z = 0;
}
box(int x, int y, int z)
{
this->x = x;
this->y = y;
this->z = z;
}
inline bool operator < (const box &other) const
{
if (this->x == other.x)
{
if (this->y == other.y)
return this->z < other.z;
return this->y < other.y;
}
return this->x < other.x;
}
};
box v[DIM];
int aib2d[DIM][DIM];
int dp[DIM];
int n, t;
inline int lsb(int x)
{
return x & (-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))
if (val != 0)
aib2d[i][j] = max(aib2d[i][j], val);
else
aib2d[i][j] = 0;
}
int Query(int x, int y)
{
int ret = 0;
for (int i = x;i >= 1;i -= lsb(i))
for (int j = y;j >= 1;j -= lsb(j))
ret = max(ret, aib2d[i][j]);
return ret;
}
void Solve()
{
int ans = -1;
for (int i = 1;i <= n;++i)
{
dp[i] = 1 + Query(v[i].y - 1, v[i].z - 1);
Update(v[i].y, v[i].z, dp[i]);
ans = max(ans, dp[i]);
}
for (int i = 1;i <= n;++i)
Update(v[i].y, v[i].z, 0);
fout << ans << "\n";
}
int main()
{
fin >> n >> t;
int x, y, z;
for (int i = 1;i <= t;++i)
{
for (int j = 1;j <= n;++j)
{
fin >> x >> y >> z;
v[j] = box(x, y, z);
}
sort(v + 1, v + n + 1);
Solve();
}
fin.close();
fout.close();
return 0;
}