Pagini recente » Cod sursa (job #1712544) | Cod sursa (job #1483197) | Cod sursa (job #1981872) | Cod sursa (job #1773326) | Cod sursa (job #2263201)
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string.h>
#define MAXN 3501
using namespace std;
int n;
struct Box {
int x, y, z;
bool operator<(Box &rhs) {
return z < rhs.z;
}
};
Box boxes[MAXN];
int aib[MAXN][MAXN];
int lsb(int x) {
return x & -x;
}
int query(int x, int y) {
int result = 0;
while (x > 0) {
int ty = y;
while (ty > 0) {
result = max(result, aib[x][ty]);
ty -= lsb(ty);
}
x -= lsb(x);
}
return result;
}
void update(int x, int y, int value) {
while (x <= n) {
int ty = y;
while (ty <= n) {
aib[x][ty] = max(aib[x][ty], value);
ty += lsb(ty);
}
x += lsb(x);
}
}
void reset(int x, int y) {
while (x <= n) {
int ty = y;
while (ty <= n) {
aib[x][ty] = 0;
ty += lsb(ty);
}
x += lsb(x);
}
}
void solve() {
int x, y, z;
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &x, &y, &z);
boxes[i] = { x,y,z };
}
sort(boxes + 1, boxes + n + 1);
int gbest = 0;
for (int i = 1; i <= n; ++i) {
int q = query(boxes[i].x, boxes[i].y);
update(boxes[i].x, boxes[i].y, q + 1);
gbest = max(q + 1, gbest);
}
for (int i = 1; i <= n; ++i) {
reset(boxes[i].x, boxes[i].y);
}
printf("%d\n", gbest);
}
int main() {
freopen("cutii.in", "r", stdin);
freopen("cutii.out", "w", stdout);
int t;
scanf("%d %d", &n, &t);
for (int i = 0; i < t; ++i) {
solve();
}
return 0;
}