Need help

Revision en1, by Loserinlife, 2024-04-30 17:01:27

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!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Loserinlife 2024-04-30 17:01:27 322 Initial revision (published)