Блог пользователя real_father_of_goku

Автор real_father_of_goku, 11 лет назад, По-английски

How can we solve spoj problem INCSEQ using segment tree?

Here is the link to the problem

http://www.spoj.com/problems/INCSEQ/

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
Rev. 6  
Проголосовать: нравится +11 Проголосовать: не нравится

I think, that you can solve this task in such way :

You will use K segment trees.

1. Sort all elements of given array in non-decreasing order.

About sort : if elements are equal — the minimal element will be element which has the rightmost position.

2. You should update every segment tree in such way :

sum = getSumOnPositionInPrevSegTree(1, myElementPosition - 1)

3. Le'ts add the value of sum in the current segment tree in position myElementPosition.

My AC code here

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Another ways to solve the problem:

  1. BIT-based: d3HGAB
  2. Merge-sort based: becXSW