Pagini recente » Cod sursa (job #651589) | Cod sursa (job #508672) | Cod sursa (job #2130704) | Cod sursa (job #1175913) | Cod sursa (job #1022271)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;
const int nmax = 3502;
int n, t;
pair<int,pair<int,int> > box[nmax];
short aib[nmax][nmax];
inline short query(int x,int y) {
short ret = 0;
for(int i = x;i > 0;i -= (i & -i)) {
for(int j = y;j > 0;j -= (j & -j)) {
ret = max(ret,aib[i][j]);
}
}
return ret;
}
inline void update(int x,int y,short 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);
}
}
}
int main()
{
freopen("cutii.in","r",stdin);
freopen("cutii.out","w",stdout);
scanf("%d %d",&n,&t);
for(int i = 0;i < t;i++) {
memset(aib,0,sizeof(aib));
for(int j = 0;j < n;j++) {
scanf("%d %d %d",&box[j].first,&box[j].second.first,&box[j].second.second);
}
sort(box,box + n);
short ans = 1;
for(int 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);
}
printf("%d\n",ans);
}
return 0;
}