Pagini recente » Cod sursa (job #1889172) | Cod sursa (job #161963) | Cod sursa (job #2454587) | Cod sursa (job #1199932) | Cod sursa (job #2910023)
#include <fstream>
#include <algorithm>
#include <string.h>
using namespace std;
const int MAX_N = 3500;
short int aib[MAX_N + 1][MAX_N + 1];
struct cutie {
int x;
int y;
int z;
};
bool operator < (const cutie &a, const cutie &b) {
return a.x < b.x;
}
cutie a[MAX_N + 1];
int n, t;
void update(int x, int y, short 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 query(int x, int y) {
short int answer = 0;
for (int i = x; i >= 1; i -= i & -i) {
for (int j = y; j >= 1; j -= j & -j) {
answer = max(answer, aib[i][j]);
}
}
return answer;
}
int main() {
ifstream fin("cutii.in");
ofstream fout("cutii.out");
fin >> n >> t;
while (t--) {
for (int i = 1; i <= n; i++) {
fin >> a[i].x >> a[i].y >> a[i].z;
}
sort(a + 1, a + n + 1);
memset(aib, 0, sizeof(aib));
int answer = 0;
for (int i = 1; i <= n; i++) {
int tmp = query(a[i].y, a[i].z) + 1;
answer = max(answer, tmp);
update(a[i].y, a[i].z, tmp);
}
fout << answer << "\n";
}
return 0;
}