Pagini recente » Cod sursa (job #1518302) | Cod sursa (job #965590) | Cod sursa (job #868784) | Profil Sava_Barbuta_Dospra | Cod sursa (job #2211230)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
const int N = 3507;
int t[N][N], n;
pair < int, pair < int, int > > c[N];
int query(pair < int, int > val) {
int ans(0);
for (int i = val.first; i > 0; i = i - (i&(-i))) {
for (int j = val.second; j > 0; j = j - (j&(-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 + (i&(-i))) {
for (int j = val2.second; j <= n; j = j + (j&(-j))) {
t[i][j] = max(t[i][j], val);
}
}
}
void lolreset(int x, int y) {
for (int i = x; i <= n; i = i + (i&(-i))) {
for (int j = y; j <= n; j = j + (j&(-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].first >> c[i].second.first >> c[i].second.second;
}
sort(c + 1, c + n + 1);
for (int i = 1; i <= n; ++i) {
int answer = query(make_pair(c[i].second.first - 1, c[i].second.first - 1)) + 1;
solution = max(solution, answer);
update(answer, c[i].second);
}
cout << query(make_pair(n, n)) << "\n";
for (int i = 1; i <= n; ++i) {
lolreset(c[i].second.first, c[i].second.second);
lolreset(c[i].second.first, c[i].second.second);
}
}
return 0;
}