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

Автор Loserinlife, история, 3 недели назад, По-английски

A function F(l, r) is defined as follow:

F(l, r) = 0 if l > r

else m is the index of the largest element from l to r.

F(l, r) = r — l + 1 + F(l, m — 1) + F(m + 1, r)

Given a permutation of length N and Q queries (l, r), calculate F(l, r) for each queries.

N <= 1e6, Q <= 1e6

Thanks!

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

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

Wasn't this a codeforces problem? Btw I want to say that while typing this comment I got dejavu

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

Wow, really cool problem. Source?

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

Observing the form of this contribution, from a different perspective, it is actually the sum of the number of elements in the left and right monotonic stacks for each number in [l, r]. Taking the inquiry offline is a basic scanning line problem that can achieve O((n+q)logn).

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

CF1117G