ASC(1)G(最长上升子序列)

G - Beautiful People

Time Limit:  10000/5000MS (Java/Others)  Memory Limit:  128000/64000KB (Java/Others)      Special Judge
Problem Description

      The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi. Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si <= Sj and Bi >= Bj or if Si >= Sj and Bi <= Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn't even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much).

      To celebrate a new 2003 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club prestige at the apropriate level, administration wants to invite as many people as possible.

      Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party.

Input
      The first line of the input file contains integer N — the number of members of the club. ( 2 ≤ N ≤ 100 000). Next N lines contain two numbers each — S i and B respectively ( 1 ≤ Si, Bi ≤ 109).
Output
      On the first line of the output file print the maximum number of the people that can be invited to the party. On the second line output N integers — numbers of members to be invited in arbitrary order. If several solutions exist, output any one.
Sample Input
4
1 1
1 2
2 1
2 2
Sample Output
2
1 4

题意:给了n个数对x,y,要求找出最长的数对,使得每一维都严格递增

思路:最长上升子序列,只不过是2维的,可以先按x排序以后按顺序用线段树维护就好了

            具体维护的是,以每个y点结尾的最大长度

            注意更新的时候先将同一个x下的y全部查询完了以后记录,再统一更新,因为x相等的点是不可以够成上升序列的

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
         #include 
        
          using namespace std; const int MAXN = 200010; struct node{ int x,y,id; }a[MAXN]; struct node1{ int v; int id; int ok; }b[MAXN<<1]; bool cmp(node1 a,node1 b) { return a.v 
         
           >q[MAXN<<1]; #define lson l,m,o<<1 #define rson m+1,r,o<<1|1 int sum[MAXN<<2]; int idd[MAXN<<2]; void pushup(int o) { sum[o]=max(sum[o<<1],sum[o<<1|1]); if(sum[o<<1]>sum[o<<1|1]){ idd[o]=idd[o<<1]; } else idd[o]=idd[o<<1|1]; } void build(int l,int r,int o) { if(l==r){ sum[o]=0; idd[o]=0; return; } int m=l+r>>1; build(lson); build(rson); pushup(o); } pair 
          
            query(int l,int r,int o,int L,int R) { if(L<=l&&r<=R){ return make_pair(sum[o],idd[o]); } int m=l+r>>1; int mx=0; pair 
           
             pii; if(L<=m){ pair 
            
              pi=query(lson,L,R); if(mx 
             
               pi=query(rson,L,R); if(mx 
              
                sum[o]){ sum[o]=v; idd[o]=v2; } return; } int m=l+r>>1; if(p<=m)update(lson,p,v,v2); else update(rson,p,v,v2); pushup(o); } struct node3{ int v1; int v2; int id; }ha[MAXN]; int pre[MAXN]; int stk[MAXN]; int main() { int n; scanf("%d",&n); int cnt=0; for(int i=1;i<=n;i++){ scanf("%d%d",&a[i].x,&a[i].y); a[i].id=i; b[cnt].v=a[i].x; b[cnt].id=i; b[cnt++].ok=0; b[cnt].v=a[i].y; b[cnt].id=i; b[cnt++].ok=1; } sort(b,b+cnt,cmp); b[cnt].v=-1; int mx=1; for(int i=0;i 
               
                 ss; int coun=1; if(v>1){ ss=query(1,mx-1,1,1,v-1); coun=ss.first+1; } ha[sz].v1=v; ha[sz].id=id; ha[sz++].v2=coun; pre[id]=ss.second; if(ans 
                
                  1)pre[id]=ss.second; } } for(int j=0;j 
                  
                 
                
               
              
             
            
           
          
         
       
      
      
     
     
    
    
   
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值