Mayor's posters POJ - 2528 tree line interval coverage

// segment tree interval coverage 
#include <cstdio> 
#include <CString> 
#include <the iostream> 
#include <algorithm>
 the using  namespace STD;
 const  int N = 100010 ;
 int In Flag;
 struct Node {
     int L, R & lt;
     // VIS if this area is completely covered 
    BOOL VIS;
}tr[N<<2];
struct point
{
    int id;
    int x;
}post[N<<2];
int cmp1(point a,point b)
{
    return a.x<b.x;
}
int cmp2(point a,point b)
{
    if(a.id==b.id)
        return a.x<b.x;
    return a.id>b.id;
}
void pushup(int u)
{
    tr[u].vis=tr[u<<1].vis&&tr[u<<1|1].vis;
}
void build(int u,int l,int r)
{
    tr[u]={l,r,0};
    if(l==r)
        return ;
    int mid=l+r>>1;
    build(u<<1,l,mid);
    build(u<<1|1,mid+1,r);
}
void query ( you and, you to, you r)
{
    if(tr[u].vis)
        return ;
    if(tr[u].l==l&&tr[u].r==r)
    {
        tr [u] .vis = 1 ;
        flag=1;
        return;
    }
    int mid=tr[u].l+tr[u].r>>1;
    if(r<=mid)
        query(u<<1,l,r);
    else if(l>mid)
        query(u<<1|1,l,r);
    else
    {
        query(u<<1,l,mid);
        query(u<<1|1,mid+1,r);
    }
    pushup(u);
}
int main ()
{
    int t,n;
    cin>>t;
    while(t--)
    {
        CIN >> n-;
         // before discrete data 
        for ( int I = 0 ; I < 2 * n-; = I + 2 )
        {
            cin>>post[i].x>>post[i+1].x;
            post[i].id=post[i+1].id=i;
        }
        // The data sorting before discretization 
        Sort (POST, POST + 2 * n-, CMP1); 
         // discretization 
        int TOT = 0 , pre = 0 ;
         for ( int I = 0 ; I < 2 * n-; I ++ )
        {
            // if the previous one 
             // then rank it as 
            IF (POST [i] .x == pre)
            {
                post [i] .x = all;
            } 
            // If not, record the current value
             // ranking ++ 
            the else
            {
                pre=post[i].x;
                post [i] .x = ++ all;
            } 
        }
        Build ( . 1 , . 1 , 2 * n-); 
         // sort, stickers from the forward
         // ID big front 
        Sort (POST, POST + 2 * n-, CMP2);
         int ANS = 0 ;
         for ( int I = 0 ; I < 2 * n-; = I + 2 )
        {
            int l=post[i].x;
            int r=post[i+1].x;
            flag=0;
            query(1,l,r);
            if(flag)
                years ++ ;
        }    
        cout<<ans<<endl;
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/12293741.html