Pagini recente » Cod sursa (job #1227585) | Cod sursa (job #88482) | Cod sursa (job #1056288) | Cod sursa (job #1632675) | Cod sursa (job #2891723)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
short n, t;
struct paralel {
short x, y, z;
};
bool cmp(paralel a, paralel b) {
if (a.x != b.x) {
return a.x < b.x;
}
else if (a.y != b.y) {
return a.y < b.y;
}
return a.z < b.z;
}
paralel c[3502];
short aib[3502][3502];
void update(short x, short y, short val) {
for (; x <= n; x += (x & -x)) {
for (int yy = y; yy <= n; yy += (yy & -yy)) {
aib[x][yy] = max(aib[x][yy], val);
}
}
}
int query(short x, short y) {
short ans = 0;
for (; x > 0; x -= (x & -x)) {
for (int yy = y; yy > 0; yy -= (yy & -yy)) {
ans = max(ans, aib[x][yy]);
}
}
return ans;
}
void clear(short x, short y) {
for (; x <= n; x += (x & -x)) {
for (int yy = y; yy <= n; yy += (yy & -yy)) {
aib[x][yy] = 0;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t;
for (short z = 1; z <= t; z++) {
for (short i = 1; i <= n; i++) {
cin >> c[i].x >> c[i].y >> c[i].z;
}
sort(c + 1, c + n + 1, cmp);
int bst = 0;
for (short i = 1; i <= n; i++) {
bst = query(c[i].y, c[i].z) + 1;
update(c[i].y, c[i].z, bst);
}
cout << query(n, n) << '\n';
for (short i = 1; i <= n; i++) {
clear(c[i].y, c[i].z);
}
}
}