Note that there are some explanatory texts on larger screens.

plurals
  1. POO(N*LogN) algorithm for the following problem
    text
    copied!<p>There is the following problem:</p> <blockquote> <p>The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, <em>i</em>-th member of this club (members being numbered by the time they entered the club) has strength S<sub><em>i</em></sub> and beauty B<sub><em>i</em></sub>. 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, <em>i</em>-th member of the club Mr X hates <em>j</em>-th member of the club Mr Y if S<sub><em>i</em></sub> ≤ S<sub><em>j</em></sub> and B<sub><em>i</em></sub> ≥ B<sub><em>j</em></sub> or if S<sub><em>i</em></sub> ≥ S<sub><em>j</em></sub> and B<sub><em>i</em></sub> ≤ B<sub><em>j</em></sub> (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).</p> <p>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.</p> <p><em>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.</em></p> <p><em><strong>Input</em></strong></p> <p>*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<sub><em>i</em></sub> and B<sub><em>i</em></sub> respectively ( 1 ≤ S<sub><em>i</em></sub>, B<sub><em>i</em></sub> ≤ 109 ).* </p> <p><em><strong>Output</em></strong></p> <p><em>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.</em></p> <p><em><strong>Sample test(s)</em></strong></p> <p><em>Input</em></p> <pre><code> 4 1 1 1 2 2 1 2 2 </code></pre> <p><em>Output</em></p> <pre><code> 2 1 4 </code></pre> </blockquote> <p>I am trying to solve a problem but the complexity of my algorithm is O(N^2) and since 2&lt;=N&lt;=100000 there is a need to improve an algorithm. I was solving the problem using longest increasing subsequence dynamic programming algorithm which has O(N^2) complexity. Does anybody have an idea how to improve the algorithm?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload