Cod sursa(job #2503724)

Utilizator TudorCaloianCaloian Tudor-Ioan TudorCaloian Data 3 decembrie 2019 18:31:29
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, t, aib[4000][4000];
pair <int, pair<int,int> > v[4000];

int Query(int x, int y)
{
    int k = 0;
    for(int i = x; i; i -= i&(-i))
        for(int j = y; j; j -= j&(-j))
            k = max(k, aib[i][j]);
    return k;
}

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))
            aib[i][j] = max(aib[i][j], value);
}
int main()
{
   fin >> n >> t;

   while(t--)
   {
       memset(aib, 0, sizeof(aib));
       memset(v, 0, sizeof(v));

        for(int i = 1; i <= n; i++) fin >> v[i].first >> v[i].second.first >> v[i].second.second;

        sort(v+1,v+1+n);
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            int x = Query(v[i].second.first-1, v[i].second.second-1)+1;
            Update(v[i].second.first, v[i].second.second, x);
            ans = max(x, ans);
        }
        fout << ans << '\n';

   }

    return 0;
}