Cod sursa(job #2328250)

Utilizator filicriFilip Crisan filicri Data 25 ianuarie 2019 15:56:19
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>
#include <algorithm>
#define nmax 3500
using namespace std;
ifstream f("cutii.in");
ofstream g("cutii.out");
int n,t,p[nmax],len;
struct s1
{
    int a,b,c;
} c[nmax];
struct s2
{
    int x,y;
} q[nmax];
bool cmp (s1 x, s1 y)
{
    return x.a>y.a;
}
int getpos (int u,int v)
{
    int low=1,hi=len;
    while (low<hi)
    {
        int mid=(low+hi)/2;
        if (q[mid].x>u && q[mid].y>v) low=mid+1;
        else hi=mid;
    }
    if (q[low].x<=u && q[low].y<=v && q[low-1].x>u && q[low-1].y>v) return low;
    return -1;
}
int sdmax (void)
{
    len=0;
    for (int i=1;i<=n;i++) q[i].x=q[i].y=p[i]=0;
    for (int i=1;i<=n;i++)
    {
        int pos=getpos(c[i].b,c[i].c);
        if (pos==-1)
        {
            len++;
            q[len].x=c[i].b;
            q[len].y=c[i].c;
            p[i]=len;
        }
        else
        {
            q[pos].x=c[i].b;
            q[pos].y=c[i].c;
        }
    }
    return len;
}
int main()
{
    f>>n>>t;
    while (t--)
    {
        for (int i=1;i<=n;i++) f>>c[i].a>>c[i].b>>c[i].c;
        sort(c+1,c+n+1,cmp);
        g<<sdmax()<<'\n';
    }
    f.close();
    g.close();
    return 0;
}