Separator
Time limit1.2sMemory limit512 MB
Append values one at a time to a growing sequence and after each append report how many indices are separators, meaning every earlier element is smaller and every later element is larger.
- Level
Hard8 of 10
- Topics
- Tree, Implementation, Binary search, Sorting
- Solved
- No attempts yet
Problem
Let be a sequence of distinct integers. An index is called a separator if the following two conditions hold:
- for all : ,
- for all : .
In other words, the array consists of three parts: all elements smaller than , then itself, and finally all elements greater than .
For instance, let . The separators are the indices 4 and 7, corresponding to the values 50 and 90.
The sequence is initially empty. You are given a sequence of elements to append to , one after another. After appending each , output the current number of separators in the sequence you have.
The input format is selected so that you have to compute the answers online. Instead of the elements you should append to , you are given a sequence .
Process the input as follows:
The empty sequence contains separators.
For each from 1 to , inclusive:
- Calculate the value .
- Append to the sequence .
- Calculate : the number of separators in the current sequence .
- Output a line containing the value .
Input
The first line contains a single integer (): the number of queries to process.
Then, lines follow. The -th of these lines contains the integer (). The values are chosen in such a way that the values you'll compute will all be distinct.
Output
As described above, output lines with the values through .
Notes
The first example is described in the problem statement.
The second example is decoded as .