Pagini recente » Cod sursa (job #2134963) | Cod sursa (job #1223521) | Cod sursa (job #2245090) | Cod sursa (job #2271815) | Cod sursa (job #2965532)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in ("cutii.in");
ofstream out ("cutii.out");
#define lsb(x)(x & (-x))
const int max_size = 3501;
struct str{
int x, y, z;
};
str cutii[max_size];
int aib[max_size][max_size], n;
void upd (int x, int y, int val)
{
for (int i = x; i <= n; i += lsb(i))
{
for (int j = y; j <= n; j += lsb(j))
{
aib[i][j] = max(aib[i][j], val);
}
}
}
int querry (int x, int y)
{
int ans = 0;
for (int i = x; i > 0; i -= lsb(i))
{
for (int j = y; j > 0; j -= lsb(j))
{
ans = max(ans, aib[i][j]);
}
}
return ans + 1;
}
void reset (int x, int y)
{
for (int i = x; i <= n; i += lsb(i))
{
for (int j = y; j <= n; j += lsb(j))
{
aib[i][j] = 0;
}
}
}
bool cmp (str a, str b)
{
return a.z < b.z;
}
void solve ()
{
for (int i = 1; i <= n; i++)
{
in >> cutii[i].x >> cutii[i].y >> cutii[i].z;
}
sort(cutii + 1, cutii + n + 1, cmp);
int ans = 1;
for (int i = 1; i <= n; i++)
{
int mx = querry(cutii[i].x - 1, cutii[i].y - 1);
upd(cutii[i].x, cutii[i].y, mx);
ans = max(ans, mx);
}
for (int i = 1; i <= n; i++)
{
reset(cutii[i].x, cutii[i].y);
}
out << ans << '\n';
}
int main ()
{
int t;
in >> n >> t;
while (t--)
{
solve();
}
in.close();
out.close();
return 0;
}