Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

The problem is: Given an array of 10^5 numbers and 10^5 queries, each query is like "i j" means: find the largest possible value A[y]-A[x] such that i<=x<=y<=j.

The analysis of this problem said it is easy to do with segment tree, but I have no idea, can anyone please explain how? (btw, it also has update operation, otherwise I could do it with offline semgment tree)

Thanks in advance!

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

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

Link to the problem?

For a node in the segment tree keep : <min,max,answer>. Now think about how you would merge two nodes.

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

for each node keep: pair<min,max>

now the answer for each query is : quermax-quermin

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