RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00089

Bst

Platinum V 플래티넘 V
난이도
1s
시간 제한
32MB
메모리 제한
3
맞았습니다!!
3
제출 수
100.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\).

제약

In test cases worth 50% of points, N will be at most 1000.
Contest #3, \(13^{th}\) December 2008

입력 형식

The first line contains the integer \(N\) (\(1 \le N \le 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.

Scoring: In test cases worth \(50\%\) of points, \(N\) will be at most \(1000\).

서브태스크
서브태스크점수설명

Subtask 1

120점
예제 1
입력
4
1
2
3
4
출력
0
1
3
6
예제 2
입력
5
3
2
4
1
5
출력
0
1
2
4
6
예제 3
입력
8
3
5
1
6
8
7
2
4
출력
0
1
2
4
7
11
13
15
문제 정보

riseoj 작성

출처 COCI 2008/2009 Contest 3

평가 및 의견

Bst

개요
출제자 난이도 Platinum V 플래티넘 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Bst

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8