Pagini recente » Cod sursa (job #2857860) | Cod sursa (job #2731798) | Cod sursa (job #3169166) | Cod sursa (job #1179298) | Cod sursa (job #1022275)
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
const short nmax = 3505;
short n, t;
pair<short,pair<short,short> > box[nmax];
short aib[nmax][nmax];
inline short query(short x,short y) {
short ret = 0;
for(short i = x;i > 0;i -= (i & -i)) {
for(short j = y;j > 0;j -= (j & -j)) {
ret = max(ret,aib[i][j]);
}
}
return ret;
}
inline void update(short x,short y,short val) {
for(short i = x;i <= n;i += (i & -i)) {
for(short j = y;j <= n;j += (j & -j)) {
aib[i][j] = max(aib[i][j],val);
}
}
}
int main()
{
cin>>n>>t;
for(short i = 0;i < t;i++) {
if(i) memset(aib,0,sizeof(aib));
for(short j = 0;j < n;j++) {
cin>>box[j].first>>box[j].second.first>>box[j].second.second;
}
sort(box,box + n,[] (const pair<short,pair<short,short> > &a,const pair<short,pair<short,short> > &b ) {
return a.first < b.first;
});
short ans = 1;
for(short j = 0;j < n;j++) {
short val = 1 + query(box[j].second.first - 1,box[j].second.second - 1);
ans = max(ans,val);
update(box[j].second.first,box[j].second.second,val);
}
cout<<ans<<"\n";
}
return 0;
}