Pagini recente » Cod sursa (job #2538747) | Cod sursa (job #1625196) | Cod sursa (job #2060166) | Cod sursa (job #1698145) | Cod sursa (job #3252476)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using TI = tuple<int, int, int>;
using VTI = vector<TI>;
int aib[3511][3511];
int NMAX = 3500;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
void Update(int x, int y, int val)
{
for (int i = x; i <= NMAX; i += i & -i)
for (int j = y; j <= NMAX; j += j & -j)
aib[x][y] = max(val, aib[i][j]);
}
int Query(int x, int y)
{
int sum = 0;
for (int i = x; i > 0; i -= i & -i)
for (int j = y; j > 0; j -= j & -j)
sum = max(aib[i][j], sum);
return sum;
}
void Reset(int x, int y)
{
for (int i = x; i <= NMAX; i += i & -i)
for (int j = y; j <= NMAX; j += j & -j)
aib[x][y] = 0;
}
int main()
{
int currmax = 0;
int a, b, c;
int n, t;
fin >> n >> t;
VTI v(n);
int a1, a2, a3;
int b1, b2, b3;
int d;
while (t--)
{
for (int i = 0; i < n; ++i)
{
fin >> a >> b >> c;
v[i] = {a, b, c};
}
sort(v.begin(), v.end());
currmax = 0;
for (auto& [a, b, c] : v)
{
Update(b + 1, c + 1, Query(b, c) + 1);
}
fout << Query(3501, 3501) << '\n';
for (auto& [a, b, c] : v)
{
Reset(b + 1, c + 1);
}
}
}