Pagini recente » Cod sursa (job #1714131) | Cod sursa (job #2682571) | Cod sursa (job #817355) | Cod sursa (job #175546) | Cod sursa (job #1223545)
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int NMAX = 3505;
struct CUTIE {
int x, y, z;
void read() {
scanf("%d%d%d", &x, &y, &z);
}
};
int n, aib[NMAX][NMAX];
CUTIE c[NMAX];
class cmp {
public:
inline bool operator () (CUTIE a, CUTIE b) {
if(a.x == b.x) {
if(a.y == b.y)
return a.z < b.z;
return a.y < b.y;
}
return a.x < b.x;
}
};
inline int lsb (int x) {
return x & -x;
}
void update (int x, int y, int val) {
int i, j;
for(i = x; i <= n; i += lsb(i))
for(j = y; j <= n; j += lsb(j))
aib[i][j] = val;
}
void updateZero (int x, int y) {
int i, j;
for(i = x; i <= n; i += lsb(i))
for(j = y; j <= n; j += lsb(j))
aib[i][j] = 0;
}
int query (int x, int y) {
int i, j, ans;
ans = 0;
for(i = x; i > 0; i -= lsb(i))
for(j = y; j > 0; j -= lsb(j))
ans = max(aib[i][j], ans);
return ans;
}
int solve() {
int k;
sort(c + 1, c + 1 + n, cmp());
//memset(aib, 0, sizeof(aib));
for(k = 1; k <= n; ++ k)
update(c[k].y, c[k].z, query(c[k].y - 1, c[k].z - 1) + 1);
return query(n, n);
}
int main() {
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int t, i;
scanf("%d%d", &n, &t);
while(t) {
-- t;
for(i = 1; i <= n; ++ i)
c[i].read();
printf("%d\n", solve());
for(i = 1; i <= n; ++ i)
updateZero(c[i].y, c[i].z);
}
return 0;
}