Pagini recente » Cod sursa (job #2759635) | Cod sursa (job #1912) | Cod sursa (job #2468898) | Cod sursa (job #2494725) | Cod sursa (job #2003895)
#include <bits/stdc++.h>
using namespace std;
struct cutie
{
int x, y, z;
cutie(int _x, int _y, int _z) : x{_x}, y{_y}, z{_z}{}
bool operator<( const cutie& c ) const {
return z < c.z;
}
};
ifstream fin("cutii.in");
ofstream fout("cutii.out");
vector<cutie>boxes;
vector<vector<int>> AIB;
int N, T;
int query(int x, int y)
{
int answ = 0;
for (int i = x; i; i -= i & -i)
for (int j = y; j; j -= j & -j)
answ = max (answ, AIB[i][j]);
return answ;
}
void update(int x, int y, int v)
{
for (int i = x; i <= N; i += i & -i)
for (int j = y; j <= N; j += j & -j)
AIB[i][j] = max (AIB[i][j], v);
}
void Clean(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;
}
int main()
{
fin >> N >> T;
AIB = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
for(; T; --T)
{
for (int i = 1, x, y, z; i <= N; ++i)
{
fin >> x >> y >> z;
boxes.push_back(cutie{x, y, z});
}
sort(boxes.begin(), boxes.end());
int myAnsw = 0;
for_each(boxes.begin(), boxes.end(), [&](const cutie& c)
{
int mM = query(c.x - 1, c.y - 1) + 1;
update(c.x, c.y, mM);
myAnsw = max(myAnsw, mM);
});
fout << myAnsw << "\n";
for_each(boxes.begin(), boxes.end(), [](const cutie& c)
{
Clean(c.x, c.y);
});
boxes.erase(boxes.begin(),boxes.end());
}
return 0;
}