Cod sursa(job #2211201)

Utilizator ContDeRacistAliniateEBlat ContDeRacist Data 9 iunie 2018 15:59:33
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

const int N = 3507;

int t[N][N];

pair < int, pair < int, int > > c[N];

int query(pair < int, int > val) {
    int ans(0);
    for (int i = val.first; i > 0; i -= i&(-i)) {
        for (int j = val.second; j > 0; j -= j&(-j)) {
            ans = max(ans, t[i][j]);
        }
    }
    return ans;
}

void update(int val, pair < int, int > val2) {
    for (int i = val2.first; i < N; i += i&(-i)) {
        for (int j = val2.second; j < N; j += j&(-j)) {
            t[i][j] = max(t[i][j], val);
        }
    }
}

void reset(int x, int y) {
    for (int i = x; i < N; i += i&(-i)) {
        for (int j = y; j < N; j += j&(-j)) {
            t[i][j] = 0;
        }
    }
}

int main()
{
    int n, t, solution(-1);
    cin >> n >> t;
    while (t--) {
        solution = -1;
        for (int i = 0; i < n; ++i) {
            cin >> c[i].first >> c[i].second.first >> c[i].second.second;
        }
        sort(c, c + n);
        for (int i = 0; i < n; ++i) {
            int answer = query(make_pair(c[i].second.first - 1, c[i].second.first - 1)) + 1;
            solution = max(solution, answer);
            update(answer, c[i].second);
        }
        for (int i = 0; i < n; ++i) {
            reset(c[i].second.first, c[i].second.second);
        }
        cout << solution << "\n";
    }
    return 0;
}