Pagini recente » Cod sursa (job #112735) | Cod sursa (job #1396884) | Cod sursa (job #2181147) | Cod sursa (job #1362978) | Cod sursa (job #2496364)
#include <bits/stdc++.h>
#define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
class Cutie {
public:
int x, y, z;
Cutie(int _x = 0, int _y = 0, int _z = 0)
: x(_x), y(_y), z(_z)
{}
bool operator < (const Cutie &c) const {
return z < c.z;
}
};
const int N = 3500;
int aib[N + 5][N + 5];
inline void Update(int cx, int cy, int val)
{
for (int x = cx; x <= N; x += x & -x)
for (int y = cy; y <= N; y += y & -y)
aib[x][y] = max(aib[x][y], val);
}
inline int Query(int cx, int cy)
{
int res = 0;
for (int x = cx; x > 0; x -= x & -x)
for (int y = cy; y > 0; y -= y & -y)
res = max(res, aib[x][y]);
return res;
}
inline void Reset(int cx, int cy)
{
for (int x = cx; x <= N; x += x & -x)
for (int y = cy; y <= N; y += y & -y)
aib[x][y] = 0;
}
int n, t, x, y, z, p;
inline int Solve(int n)
{
vector<Cutie> vc;
for (int i = 1; i <= n; i++)
{
fin >> x >> y >> z;
vc.emplace_back(Cutie(x, y, z));
}
sort(vc.begin(), vc.end());
int res = 0;
for (const auto& c : vc)
{
p = Query(c.x - 1, c.y - 1) + 1;
Update(c.x, c.y, p);
res = max(res, p);
}
for (const auto& c : vc)
Reset(c.x, c.y);
return res;
}
int main()
{
DAU
fin >> n >> t;
for (int i = 1; i <= t; ++i)
fout << Solve(n) << '\n';
PLEC
}