Pagini recente » Cod sursa (job #2601480) | Cod sursa (job #1721534) | Cod sursa (job #2470324) | Cod sursa (job #1862558) | Cod sursa (job #1465938)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
const int boxes = 3510;
int n, t;
int aib[boxes][boxes];
pair < int, pair < int, int> > p[boxes];
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.first >> p[i].second.second;
sort(p + 1, p + n + 1 );
for (int i = 1; i <= n; i++){
int now = query(p[i].second.first - 1, p[i].second.second - 1) + 1;
update(p[i].second.first, p[i].second.second, now);
nowMax = max(nowMax, now);
}
fout << nowMax << "\n";
}
return 0;
}