Cod sursa(job #3196508)

Utilizator not_anduAndu Scheusan not_andu Data 24 ianuarie 2024 09:48:19
Problema Cutii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <bits/stdc++.h>
#pragma GCC optimize ("03")

using namespace std;

#define INFILE "cutii.in"
#define OUTFILE "cutii.out"

const int MINIM = -1;
const int N_MAX = 3501;

struct Box {

    int x, y, z;

    Box() : x(0), y(0), z(0) {}
    Box(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}

    bool operator<(const Box &other) const {
        return (this -> x < other.x);
    }

};

int n;
int bit[N_MAX][N_MAX];

int query(int x, int y){
    int ans = MINIM;
    for(int i = x; i > 0; i -= (i & -i)){
        for(int j = y; j > 0; j -= (j & -j)){
            ans = max(ans, bit[i][j]);
        }
    }
    return ans;
}

void update(int x, int y, int value){
    for(int i = x; i <= n; i += (i & -i)){
        for(int j = y; j <= n; j += (j & -j)){
            bit[i][j] = max(bit[i][j], value);
        }
    }
}

void solve(){

    int ans = 0;
    vector<Box> v(n);

    for(int i = 0; i < n; ++i){
        int x, y, z; cin >> x >> y >> z; v[i] = Box(x, y, z);
    }

    sort(v.begin(), v.end());

    for(int i = 0; i < n; ++i){
        int aux = query(v[i].y, v[i].z) + 1;
        update(v[i].y, v[i].z, aux);
        ans = max(ans, aux);
    }

    cout << ans << '\n';

    memset(bit, 0, sizeof bit);

}

int main(){
    ios_base::sync_with_stdio(false);
    freopen(INFILE, "r", stdin);
    freopen(OUTFILE, "w", stdout);
    cin.tie(0), cout.tie(0);
    int tests; cin >> n >> tests;
    while(tests--) solve();
    return 0;
}