Pagini recente » Cod sursa (job #1062523) | Cod sursa (job #803643) | Cod sursa (job #1580962) | Cod sursa (job #325283) | Cod sursa (job #2323445)
#define DM 3501
#include <algorithm>
#include <cstring>
#include <fstream>
using namespace std;
ifstream fi ("cutii.in");
ofstream fo ("cutii.out");
char lst[DM][DM];
int n, t, aux, aib[DM][DM];
struct cutie {
int x, y, z;
bool operator < (const cutie &other) const {
if (x != other.x)
return x > other.x;
if (y != other.y)
return y > other.y;
return z > other.z;
}
} v[DM];
void update(int x, int y, int val) {
int cx, cy, ix;
ix = x;
while (y) {
x = ix;
while (x) {
cx = x - 1;
cx = cx^x;
cx = cx&x;
if (lst[x][y] == t) {
aib[x][y] = max(aib[x][y], val);
} else {
lst[x][y] = t;
aib[x][y] = val;
}
x-=cx;
}
cy = y - 1;
cy = cy^y;
cy = cy&y;
y-=cy;
}
}
int query(int x, int y) {
int cx, cy, ix, sol = 0;
ix = x;
while (y <= n) {
x = ix;
while (x <= n) {
cx = x - 1;
cx = cx^x;
cx = cx&x;
if (lst[x][y] == t)
sol = max(sol, aib[x][y]);
x+=cx;
}
cy = y - 1;
cy = cy^y;
cy = cy&y;
y+=cy;
}
return sol;
}
int main() {
fi >> n >> t;
while (t--) {
for (int i = 1; i <= n; ++i)
fi >> v[i].x >> v[i].y >> v[i].z;
sort(v + 1, v + 1 + n);
for (int i = 1; i <= n; ++i) {
aux = query(v[i].y, v[i].z);
update(v[i].y, v[i].z, aux + 1);
}
fo << query(1, 1) << '\n';
}
return 0;
}