Pagini recente » Cod sursa (job #2910026) | Cod sursa (job #371016) | Cod sursa (job #101036) | Cod sursa (job #1026037) | Cod sursa (job #1959429)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
struct Cutie
{
int x, y, z;
bool operator < (const Cutie &c) const
{
return z < c.z;
}
};
int n,t;
int aib[3501][3501]; // aib[x][y] - nr max de cutii cu _x < x si _y < y
void Update(int x, int y, int v)
{
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], v);
}
int Query(int x, int y)
{
int ans = 0;
for (int i = x; i >= 1; i -= i & -i)
for (int j = y; j >= 1; j -= j & -j)
ans = max(ans, aib[i][j]);
return ans;
}
void Reset(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;
}
int Solve(int n)
{
vector<Cutie> C;
int x, y, z;
for (int i = 1; i <= n; i++)
{
fin >> x >> y >> z;
C.push_back({x, y, z});
}
sort(C.begin(), C.end());
int ans = 0;
for (const auto& c : C)
{
int d = Query(c.x - 1, c.y - 1) + 1;
Update(c.x, c.y, d);
ans = max(ans, d);
}
for (const auto& c : C) Reset(c.x, c.y);
return ans;
}
int main()
{
fin >> n >> t;
for(int i = 1; i <= t; i++)
fout << Solve(n) << '\n';
return 0;
}