Pagini recente » Cod sursa (job #916864) | Cod sursa (job #133568) | Cod sursa (job #1762944) | Cod sursa (job #3138328) | Cod sursa (job #991126)
Cod sursa(job #991126)
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#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();
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;
//vector<vector<int> > _data;
};
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;
//this->_data.resize(_maxI + 1, vector<int>(_maxJ + 1, 0));
}
inline void Aib2DMax::Reset()
{
for(short i = 0; i <= _maxI; i++)
{
for(short j = 0; j <= _maxJ; j++)
{
_data[i][j] = 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);
aib.Reset();
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);
}
fout << sol << "\n";
}
fin.close();
fout.close();
}