Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

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

How can we solve spoj problem INCSEQ using segment tree?

Here is the link to the problem

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

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

»
9 лет назад, # |
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

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

Another ways to solve the problem:

  1. BIT-based: d3HGAB
  2. Merge-sort based: becXSW
  • »
    »
    9 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Can you please explain how BIT is working for this problem? Also , why we need to increment a[i] during scanning the input

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Increment is because BIT is 1-based structure. Bit-based solution is simply in k turns calculate on each turn number of sequences of length i ending in pos.