ASC (1) g (longest ascending subsequence)

Source: Internet
Author: User
G-beautiful people Time limit:10000/5000 ms (Java/Others) Memory limit:128000/64000 KB (Java/others) Special judgesubmitstatusproblem 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 wowould simultaneouly attend the party, after a drink or two they wowould start a fight. so no two people who hate each other shoshould be invited. on the other hand, to keep the club prestige at the apropriate level, administration wants to invite as your people as possible.

Being the only one among administration who is not afraid of touching a computer, you are to write a program which wocould 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-Si AND Bi 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
41 11 22 12 2
Sample output
21 4

N number pairs X and Y are given, and the longest number pair is required to make each dimension increase progressively.
Idea: the longest ascending subsequence is only a two-dimensional sequence. You can sort the sequence by X and then use the line segment tree for maintenance.
The specific maintenance is the maximum length ending with each y point.
Note that during the update process, all the records under the same X are queried and then updated in a unified manner, because the points with the same X cannot be enough for the ascending sequence.

ASC (1) g (longest ascending subsequence)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.