Pagini recente » Cod sursa (job #1579961) | Cod sursa (job #44653) | Cod sursa (job #2894320) | Cod sursa (job #614802) | Cod sursa (job #1022277)
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
const int nmax = 3505;
int n, t;
pair<int,pair<int,int> > box[nmax];
int aib[nmax][nmax];
inline int query(int x,int y) {
int 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,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);
}
}
}
int main()
{
cin>>n>>t;
for(int i = 0;i < t;i++) {
for(int j = 0;j < n;j++) {
cin>>box[j].first>>box[j].second.first>>box[j].second.second;
}
sort(box,box + n);
int ans = 1;
for(int j = 0;j < n;j++) {
int 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";
for(int j = 0;j < n;j++) {
update(box[j].second.first,box[j].second.second,0);
}
}
return 0;
}