Cod sursa(job #2937741)

Utilizator _andrei4567Stan Andrei _andrei4567 Data 10 noiembrie 2022 21:43:12
Problema Cutii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.53 kb
#include <fstream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <cstring>
#define mt make_tuple
#define lsb(x) x & (-x)

using namespace std;

ifstream cin ("cutii.in");
ofstream cout ("cutii.out");

using tu = tuple <int, int, int>;

const int N = 3500;
int aib[N + 1][N + 1];

int n, t, x, y, z;

void update (int posx, int posy, int val)
{
    for (int i = posx; i <= n; i += lsb(i))
        for (int j = posy; j <= n; j += lsb(j))
            aib[i][j] = max (aib[i][j], val);
}

int query (int posx, int posy)
{
    int mx = 0;
    for (int i = posx; i >= 1; i -= lsb(i))
        for (int j = posy; j >= 1; j -= lsb(j))
            mx = max (mx, aib[i][j]);
    return mx;
}

void erase1 (int posx, int posy)
{
    for (int i = posx; i <= n; i += lsb(i))
        for (int j = posy; j <= n; j += lsb(j))
            aib[i][j] = 0;
}

void solve ()
{
    vector <tu> v;
    for (int i = 1; i <= n && cin >> x >> y >> z; ++i)
        v.push_back (mt(x, y, z));
    sort (v.begin(), v.end(), [](const tu &a, const tu &b)
    {
        return get<0>(a) < get<0>(b);
    });
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        tie (x, y, z) = v[i];
        int val = query (y, z) + 1;///i -> cutia de jos
        ans = max (ans, val);
        update (y, z, val);
    }
    cout << ans << '\n';
    for (int i = 0; i < n; ++i)
    {
        tie (x, y, z) = v[i];
        erase1(y, z);
    }
}

int main()
{
    for (cin >> n >> t; t; --t)solve();
    return 0;
}