Pagini recente » Cod sursa (job #3305281) | Cod sursa (job #741331) | Cod sursa (job #794174) | Cod sursa (job #579826) | Cod sursa (job #3341499)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
const int NMAX = 3500;
int n, t;
tuple<int, int, int> a[NMAX + 1];
struct AIB {
int n;
int aib[NMAX + 1][NMAX + 1];
void init(int n) {
this->n = n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
aib[i][j] = 0;
}
}
}
void update(int pos_i, int pos_j, int value) {
for(int i = pos_i; i <= n; i += i & (-i)) {
for(int j = pos_j; j <= n; j += j & (-j)) {
aib[i][j] = max(aib[i][j], value);
}
}
}
int query(int pos_i, int pos_j) {
int answer = 0;
for(int i = pos_i; i >= 1; i -= i & (-i)) {
for(int j = pos_j; j >= 1; j -= j & (-j)) {
answer = max(answer, aib[i][j]);
}
}
return answer;
}
}aib;
void test_case() {
for(int i = 1; i <= n; i++) {
int x, y, z;
fin >> x >> y >> z;
a[i] = {x, y, z};
}
sort(a + 1, a + n + 1);
aib.init(n);
int answer = 0;
for(int i = 1; i <= n; i++) {
auto [x, y, z] = a[i];
int dp_here = aib.query(y - 1, z - 1) + 1;
answer = max(answer, dp_here);
aib.update(y, z, dp_here);
}
fout << answer << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fin >> n >> t;
while(t--) {
test_case();
}
return 0;
}