Cod sursa(job #2518772)

Utilizator vlad082002Ciocoiu Vlad vlad082002 Data 6 ianuarie 2020 16:34:46
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

ifstream fin("cutii.in");
ofstream fout("cutii.out");

struct cutie {
    int x, y, z;
    bool operator<(const cutie &other) const {
        return x < other.x && y < other.y && z < other.z;
    }
} v[3510];

int n, t;
vector<cutie> p;

void cb(int st, int dr, int index) {
    if(!p.size() || p[p.size()-1] < v[index]) {
        p.push_back(v[index]);
        return;
    }
    if(!(p[0] < v[index])) {
        p[0] = v[index];
        return;
    }
    while(dr-st-1 > 0) {
        int m = (st+dr) / 2;
        if(p[m] < v[index]) st = m;
        else dr = m;
    }
    p[dr] = v[index];
}

void solve() {
    while(t--) {
        for(int i = 1; i <= n; i++)
            fin >> v[i].x >> v[i].y >> v[i].z;

        sort(v+1, v+n+1);
        p.clear();
        for(int i = 1; i <= n; i++)
            cb(0, p.size()-1, i);

        fout << p.size() << '\n';
    }
}

int main() {
    fin >> n >> t;
    solve();
}