Pagini recente » Cod sursa (job #426626) | Cod sursa (job #476459) | Cod sursa (job #701001) | Cod sursa (job #636905) | Cod sursa (job #2505776)
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#define DEBUG 1
using namespace std;
ifstream in("cutii.in");
ofstream out("cutii.out");
int n, t;
pair<int, pair<int, int>> v[4001];
int tree[4001][4001];
void update(int x, int y, int val)
{
for(int i = x; i <= n; i += i&-i)
for(int j = y; j <= n; j += j&-j)
tree[i][j] = max(val, tree[i][j]);
}
int query(int x, int y)
{
int s = 0;
for(int i = x; i; i -= i&-i)
for(int j = y; j; j -= j&-j)
s = max(s, tree[i][j]);
return s;
}
void wipe(int x, int y)
{
for(int i = x; i <= n; i+= i&-i)
for(int j = y; j <= n; j += j&-j)
tree[i][j] = 0;
}
int main()
{
in >> n >> t;
while(t--)
{
for(int i = 1; i <= n; i++)
in >> v[i].first >> v[i].second.first >> v[i].second.second;
sort(v+1, v+n+1);
for(int i = 1; i <= n; i++)
{
int rez = query(v[i].second.first-1, v[i].second.second-1);
update(v[i].second.first, v[i].second.second, rez+1);
}
out << query(n, n) << '\n';
for(int i = 1; i <= n; i++)
wipe(v[i].second.first, v[i].second.second);
}
return 0;
}