Pagini recente » Cod sursa (job #2702022) | Cod sursa (job #2632812) | Cod sursa (job #2458221) | Cod sursa (job #1404041) | Cod sursa (job #1718283)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
struct what {
int first, second, third;
};
const int boxes = 3503;
int n, t;
int aib[boxes][boxes], d[boxes];
what p[boxes];
inline bool Cmp (const what &a, const what &b){
return a.first < b.first;
}
inline 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)
aib[i][j] = max(aib[i][j], val);
}
inline int query (int x, int y){
int here = 0;
for (int i = x; i; i -= i & -i)
for (int j = y ; j ; j -= j & -j)
here = max(here, aib[i][j]);
return here;
}
int main(){
ifstream fin ("cutii.in");
ofstream fout ("cutii.out");
fin >> n >> t;
for (; t; -- t){
memset(aib, 0, sizeof(aib));
int nowMax = 0;
for (int i = 1; i <= n; i++)
fin >> p[i].first >> p[i].second >> p[i].third;
sort(p + 1, p + n + 1, Cmp);
for (int i = 1; i <= n; i++){
int now = query(p[i].second - 1, p[i].third - 1) + 1;
d[i] = now;
update(p[i].second, p[i].third, d[i]);
nowMax = max(nowMax, d[i]);
}
fout << nowMax << "\n";
}
return 0;
}