Cod sursa(job #1465931)

Utilizator lflorin29Florin Laiu lflorin29 Data 28 iulie 2015 12:18:41
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;

struct what {
    int first, second, third;
};

const int boxes = 3503;
int n, t;
int aib[boxes][boxes], d[boxes];
what p[boxes];

inline bool Cmp (const what &a, const what &b){
        return a.first < b.first;
}

inline void update (int x, int y, int val){
    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], val);
}

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

int main(){
    ifstream fin ("cutii.in");
    ofstream fout ("cutii.out");
    fin >> n >> t;
    for (; t; -- t){
         memset(aib, 0, sizeof(aib));
         int nowMax = 0;
          for (int i = 1; i <= n; i++)
              fin >> p[i].first >> p[i].second >> p[i].third;
          sort(p + 1, p + n + 1, Cmp);
          for (int i = 1; i <= n; i++){
            int now = query(p[i].second - 1, p[i].third - 1) + 1;
            d[i] = now;
            update(p[i].second, p[i].third, d[i]);
            nowMax = max(nowMax, d[i]);
    }
    fout << nowMax << "\n";
}
    return 0;
}