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

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

i started to thinking about segment tree to solve this problem.

LightOj -1089

But after i noticed the range [0, 10^8], i just stucked there and couldn't managed how to solve it. please help ... thnx in advance :) :)

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

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

But after i noticed the range [0, 10^8], i just stucked there and couldn't managed how to solve it

You have to think about the amount of distinct numbers you have (at most: 2 × 50 000 for the ranges, plus 50 000 for the query points).

For example, if I give you these ranges: [1, 60 000 000], [40 000 000, 90 000 000] and these query points: 1 000 000, 50 000 000, 100 000 000, then you can reduce the problem (without changing the final answer) to a smaller problem. In this case, the ranges become: [1, 5], [3, 6], and the query points become: 2, 4, 7. For "both problems", the answers are 1, 2, 0.

P.S. note that (once you solved the "reduction" part) you can solve this problem also by using a binary indexed tree (with a trick I explained here) which can be easier than a range tree.

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

    I don't understand how to do the reduction part. How you reduce this one -> [1, 60 000 000], [40 000 000, 90 000 000] and these query points: 1 000 000, 50 000 000, 100 000 000 to this one [1, 5], [3, 6], and the query points become: 2, 4, 7 Both are quite different. isn't it?

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

The problem can easily be solved using upper_bound and lower_bound . Just sort up the left points in a vector and the right point in another vector