Pagini recente » Cod sursa (job #1420397) | Cod sursa (job #2781380) | Cod sursa (job #836785) | Cod sursa (job #547142) | Cod sursa (job #2703799)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
class box {
public:
int x, y, z;
bool operator < (const box &A) const {
return z < A.z;
}
};
const int NMAX = 3501;
int N, T, aib[NMAX][NMAX];
void max_self(int &a, int b) {
a = max(a, b);
}
void update(int x, int y, int val) {
for(int i = x; i <= N; i += i & -i)
for(int j = y; j <= N; j += j & -j)
max_self(aib[i][j], val);
}
int query(int x, int y) {
int ans = 0;
for(int i = x; i > 0; i -= i & -i)
for(int j = y; j > 0; j -= j & -j)
max_self(ans, aib[i][j]);
return ans;
}
void del(int x, int y) {
for(int i = x; i <= N; i += i & -i)
for(int j = y; j <= N; j += j & -j)
aib[i][j] = 0;
}
void test_case() {
vector<box> a(N);
for(box &x : a)
fin >> x.x >> x.y >> x.z;
sort(a.begin(), a.end());
for(const box &x : a) {
int val = query(x.x, x.y) + 1;
update(x.x, x.y, val);
}
fout << query(N, N) << '\n';
for(const box &x : a)
del(x.x, x.y);
}
int main() {
fin >> N >> T;
while(T--)
test_case();
}