Pagini recente » Cod sursa (job #2134370) | Cod sursa (job #1327434) | Cod sursa (job #1331809) | Cod sursa (job #2497552) | Cod sursa (job #2503728)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
int n, t, aib[4000][4000];
pair <int, pair<int,int> > v[4000];
int Query(int x, int y)
{
int k = 0;
for(int i = x; i; i -= i&(-i))
for(int j = y; j; j -= j&(-j))
k = max(k, aib[i][j]);
return k;
}
void Update(int x, int y, int value)
{
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], value);
}
void clear(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 main()
{
fin >> n >> t;
while(t--)
{
for(int i = 1; i <= n; i++) fin >> v[i].first >> v[i].second.first >> v[i].second.second;
sort(v+1,v+1+n);
int ans = 0;
for(int i = 1; i <= n; i++)
{
int x = Query(v[i].second.first-1, v[i].second.second-1)+1;
Update(v[i].second.first, v[i].second.second, x);
ans = max(x, ans);
}
fout << ans << '\n';
for(int i = 1; i <= n; i++) clear(v[i].second.first, v[i].second.second);
}
return 0;
}