#925
Gold III
BST
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

A binary search tree is a tree in which every node has at most two children nodes (a left and a right child). Each node has an integer written inside it. If the number X is written inside a node, then the numbers in its left subtree are less than X and the numbers in its right subtree are greater than X. You will be given a sequence of integers between 1 and N (inclusive) such that each number appears in the sequence exactly once. You are to create a binary search tree from the sequence, putting the first number in the root node and inserting every other number in order. In other words, run insert(X, root) for every other number: insert( number X, node N )

increase the counter C by 1

if X is less than the number in node N

if N has no left child

create a new node with the number X and set it to be the left child of node N

else

insert(X, left child of node N)

else (X is greater than the number in node N)

if N has no right child

create a new node with the number X and set it to be the right child of node N

else

insert(X, right child of node N) Write a program that calculates the value of the counter C after every number is inserted. The counter is initially 0.

입력

The first line contains the integer N (1 ≤ N ≤ 300 000), the length of the sequence. The remaining N lines contain the numbers in the sequence, integers in the interval [1, N]. The numbers will be distinct.

출력

Output N integers each on its own line, the values of the counter C after each number is inserted into the tree.

예제 입력 1

4
1
2
3
4

예제 출력 1

0
1
3
6

예제 입력 2

5
3
2
4
1
5

예제 출력 2

0
1
2
4
6

예제 입력 3

8
3
5
1
6
8
7
2
4

예제 출력 3

0
1
2
4
7
11
13
15
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.