Cod sursa(job #2564124)

Utilizator DeniszPop Denis Denisz Data 1 martie 2020 18:22:15
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.78 kb
#include <fstream>
#include <vector>
#include <bitset
#include <cstring>
#include <iomanip>

using namespace std;

const int MAXN = 3505;
const int oo = 0x3f3f3f3f;

typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;

struct bo
{
    int x, y, z;
} box[MAXN];
struct ClassComp
{
    inline bool operator () (const bo &a, const bo &b) const
    {
        return a.z < b.z;
    }
};

int N, T, Ans;
int aib[MAXN][MAXN];

inline int lsb(int bit)
{
    return (bit ^ (bit - 1) & bit);
}
inline void Update(int x, int y, int value)
{
    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], value);
}
inline void clearAib(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;
}
inline int Query(int x, int y)
{
    int ret = 0;
    for(int i = x ; i > 0 ; i -= lsb(i))
        for(int j = y ; j > 0 ; j -= lsb(j))
            ret = max(aib[i][j], ret);
    return ret;
}
inline void Clear()
{
    for(int i = 1 ; i <= N ; ++ i)
        clearAib(box[i].x, box[i].y);
    Ans = 0;
}

int main()
{
    ifstream cin("cutii");
    ofstream cout("cutii");
    cin>>N>>T;
    while(--T)
    {
        for(int i = 1 ; i <= N ; ++ i)
            cin >> box[i].x >> box[i].y >> box[i].z;
        sort(box + 1, box + N + 1, ClassComp());
        for(int i = 1 ; i <= N ; ++ i)
        {
            int actMax = Query(box[i].x - 1, box[i].y - 1) + 1;
            Update(box[i].x, box[i].y, actMax);
            Ans = max(Ans, actMax);
        }
        cout << Ans << endl;
        for(int i = 1 ; i <= N ; ++ i)
            clearAib(box[i].x, box[i].y);
        Ans = 0;
    }
    return 0;
}