Pagini recente » Cod sursa (job #1446769) | Cod sursa (job #884678) | Cod sursa (job #2363775) | Cod sursa (job #2055667) | Cod sursa (job #2212392)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
const int N = 3502;
int t[N][N], n;
int functiegay(int val) {
return (val&(-val));
}
struct MLI {
int x, y, z;
bool operator<(MLI a) {
return x < a.x;
}
} c[N];
int query(pair < int, int > val) {
int ans(0);
for (int i = val.first; i > 0; i = i - functiegay(i)) {
for (int j = val.second; j > 0; j = j - functiegay(j)) {
ans = max(ans, t[i][j]);
}
}
return ans;
}
void update(int val, pair < int, int > val2) {
for (int i = val2.first; i <= n; i = i + functiegay(i)) {
for (int j = val2.second; j <= n; j = j + functiegay(j)) {
t[i][j] = max(t[i][j], val);
}
}
}
void lolreset(int x, int y) {
for (int i = x; i <= n; i = i + functiegay(i)) {
for (int j = y; j <= n; j = j + functiegay(j)) {
t[i][j] = 0;
}
}
}
int main()
{
int t, solution(-1);
cin >> n >> t;
for (int lolol = 0; lolol < t; ++lolol) {
solution = -1;
for (int i = 1; i <= n; ++i) {
cin >> c[i].x >> c[i].y >> c[i].z;
}
sort(c + 1, c + n + 1);
for (int i = 1; i <= n; ++i) {
int answer = query(make_pair(c[i].y - 1, c[i].z - 1)) + 1;
solution = max(solution, answer);
update(answer, make_pair(c[i].y, c[i].z));
}
cout << query(make_pair(n, n)) << "\n";
for (int i = 1; i <= n; ++i) {
lolreset(c[i].y, c[i].z);
}
}
return 0;
}