G - Beautiful People
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
Output
Sample Input
4 1 1 1 2 2 1 2 2
Sample Output
2 1 4
#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