Zoj 2319 beautiful people

Source: Internet
Author: User
Beautiful peopletime limit: 5000 msmemory limit: 32768 kbthis problem will be judged on zju. Original ID: 2319
64-bit integer Io format: % LLD Java class name: mainspecial judge

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 speaki Ng, 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 2005 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.


This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. each input block is in the format indicated in the Problem description. there is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.


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

1

4
1 1
1 2
2 1
2 2


Sample output

2
1 4


Sourceandrew stankevich's contest #1 problem: convert it into a lis model... The key is the path output ......
1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cmath> 5 # include <algorithm> 6 # include <climits> 7 # include <vector> 8 # include <queue> 9 # include <cstdlib> 10 # include <string> 11 # include <set> 12 # include <stack> 13 # define ll long long14 # define PII pair <int, int> 15 # define INF 0x3f3f3f16 using namespace STD; 17 const int maxn = 100010; 18 struct people {19 int S, B, ID; 20 }; 21 people P [maxn]; 22 int Q [maxn], path [maxn], TOT; 23 bool CMP (const people & X, const people & Y) {24 if (X. S = y. s) return X. b> Y. b; 25 return X. S <Y. s; 26} 27 int bsearch (INT low, int high, int Val) {28 while (low <= high) {29 int mid = (low + high)> 1; 30 if (P [Q [Mid]. B <Val) Low = Mid + 1; 31 else high = mid-1; 32} 33 return low; 34} 35 int main () {36 int t, n, Len; 37 scanf ("% d", & T); 38 While (t --) {39 Scan F ("% d", & N); 40 for (INT I = Len = 0; I <n; I ++) {41 scanf ("% d ", & P [I]. s, & P [I]. b); 42 p [I]. id = I + 1; 43} 44 sort (p, p + N, CMP); 45 Q [Len ++] = 0; 46 path [0] = 0; 47 for (INT I = 1; I <n; I ++) {48 if (P [I]. b> P [Q [len-1]. b) {49 path [I] = Q [len-1]; // record the position of the element prior to it 50 Q [Len ++] = I; 51} else {52 int Index = bsearch (0, len-1, P [I]. b); 53 path [I] = index? Q [index-1]: 0; 54 Q [Index] = I; 55} 56} 57 printf ("% d \ n", Len ); 58 printf ("% d", P [Q [len-1]. ID); 59 int TMP = Q [len-1]; 60 while (-- Len) {61 TMP = path [TMP]; 62 printf ("% d", P [TMP]. ID); 63} 64 puts (""); 65} 66 return 0; 67}
View code

 

Zoj 2319 beautiful people

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.