Pagini recente » Cod sursa (job #2801360) | Cod sursa (job #1873261) | Cod sursa (job #1886769) | Cod sursa (job #1679966) | Cod sursa (job #463790)
Cod sursa(job #463790)
#include<fstream>
#include<algorithm>
using namespace std;
struct point
{
int x, y, z;
};
bool cmp(point a, point b)
{
return a.z <= b.z;
}
void clear(int p1, int p2);
void update(int p1, int p2, int val);
int query(int p1, int p2);
int n, t, aib[3501][3501], i;
point p[3501];
int main()
{
ifstream fin("cutii.in");
ofstream fout("cutii.out");
fin >> n >> t;
for (i = 1; i <= t; ++i)
{
int mx = 0;
for (int j = 1; j <= n; ++j)
fin >> p[j].x >> p[j].y >> p[j].z;
sort(p + 1, p + n + 1, cmp);
for (int j = 1; j <= n; ++j)
{
int x = query(p[j].x, p[j].y);
update(p[j].x, p[j].y, x + 1);
if (x + 1 > mx)
mx = x + 1;
}
for (int j = 1; j <= n; ++j)
clear(p[j].x, p[j].y);
fout << mx << '\n';
}
}
void clear(int p1, int p2)
{
for (; p1 <= n; p1 += p1 & -p1)
{
int aux = p2;
for (; aux <= n; aux += aux & -aux)
aib[p1][aux] = 0;
}
}
void update(int p1, int p2, int val)
{
for (; p1 <= n; p1 += p1 & -p1)
{
int aux = p2;
for (; aux <= n; aux += aux & -aux)
if (val > aib[p1][aux])
aib[p1][aux] = val;
}
}
int query(int p1, int p2)
{
int mx = 0;
for (; p1 >= 1; p1 -= p1 & -p1)
{
int aux = p2;
for (; aux >= 1; aux -= aux & -aux)
if (aib[p1][aux] > mx)
mx = aib[p1][aux];
}
return mx;
}