Pagini recente » Cod sursa (job #3323984) | Cod sursa (job #3323983)
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
#define pp pair<int, pair<int, int>>
int aib[3505][3505];
int n, t;
int ub(int x)
{
return (x & -x);
}
void update(int x, int y, int val)
{
for (int i = x; i <= n; i += ub(i))
{
for (int j = y; j <= n; j += ub(j))
{
aib[i][j] = max(val, aib[i][j]);
}
}
}
int query(int x, int y)
{
int maxx = 0;
for (int i = x; i >= 1; i -= ub(i))
{
for (int j = y; j >= 1; j -= ub(j))
{
maxx = max(maxx, aib[i][j]);
}
}
return maxx;
}
int main()
{
fin >> n >> t;
while (t--)
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
aib[i][j] = 0;
vector<pp> v;
for (int i = 0; i < n; i++)
{
int a, b, c;
fin >> a >> b >> c;
v.push_back({a, {b, c}});
}
sort(v.begin(), v.end());
int ans = 0;
for (int i = 0; i < n; i++)
{
int x = v[i].second.first;
int y = v[i].second.second;
int bestBefore = query(x - 1, y - 1);
int cur = bestBefore + 1;
update(x, y, cur);
ans = max(cur, ans);
// fout << v[i].first << " " << v[i].second.first << " " << v[i].second.second << '\n';
}
fout << ans;
fout << endl;
}
return 0;
}