Pagini recente » Cod sursa (job #1541829) | Cod sursa (job #1970890) | Cod sursa (job #823429) | Cod sursa (job #2665446) | Cod sursa (job #1017526)
#include <fstream>
using namespace std;
const string file = "cutii"; const string infile = file + ".in"; const string outfile = file + ".out";
struct Cutie
{short x;short y;short z;
Cutie(short x = 0, short y = 0, short z = 0)
{
this->x = x; this->y = y; this->z = z;
}
bool operator < (const Cutie& other) const
{
return this->z < other.z;
}
};
const int MAXN = 3505;
Cutie cutii[MAXN];
short _data[MAXN][MAXN];
class Aib2DMax
{
public:
static short zeros(short x);
Aib2DMax(const short maxI, const short maxJ);
void Reset(const short i, const short j); void Update(const short i, const short j, const short val);
short Query(const short i, const short j);
protected:
private:
short _maxI;short _maxJ;
};
inline short Aib2DMax::zeros(short x)
{
return (x ^ (x - 1)) & x;
}
Aib2DMax::Aib2DMax(const short maxI, const short maxJ)
{
this->_maxI = maxI;
this->_maxJ = maxJ;
}
inline void Aib2DMax::Reset(const short i, const short j)
{
for(short x = i; x <= _maxI; x += zeros(x))
{
for(short y = j; y <= _maxJ; y += zeros(y))
{
_data[x][y] = 0;
}
}
}
inline void Aib2DMax::Update(const short i, const short j, const short value)
{
for(short x = i; x <= _maxI; x += zeros(x))
{
for(short y = j; y <= _maxJ; y += zeros(y))
{
_data[x][y] = max(_data[x][y], value);
}
}
}
inline short Aib2DMax::Query(const short i, const short j)
{
short maxi = 0;
for(short x = i; x > 0; x -= zeros(x))
{
for(short y = j; y > 0; y -= zeros(y))
{
maxi = max(maxi, _data[x][y]);
}
}
return maxi;
}
int main()
{
short N, T;
fstream fout(outfile.c_str(), ios::out); fstream fin(infile.c_str(), ios::in);
fin >> N >> T;
Aib2DMax aib(N, N);
for(short i = 0; i < T; i++)
{
for(short j = 1; j <= N; j++)
{
fin >> cutii[j].x >> cutii[j].y >> cutii[j].z;
}
short sol = 0;
sort(cutii + 1, cutii + N + 1);
for(short i = 1; i <= N; i++)
{
short c = aib.Query(cutii[i].x - 1, cutii[i].y - 1) + 1;
aib.Update(cutii[i].x, cutii[i].y, c);
sol = max(sol, c);
}
for(short i = 1; i <= N; i++)
{
aib.Reset(cutii[i].x, cutii[i].y);
}
fout << sol << "\n";
}
fin.close();
fout.close();
}