Create a data structure to perform inverse queries and report queries in poly-logarithmic time

Given a sequence of n numbers, {a 1 , a 2 , a 3 , ..., a nsub>}. Create a data structure so that the following operations are performed during polyling.

  • Inverse (i, j):

    Flip all the elements in the range from i to j, as shown below:
      Original sequence: <... a i-1 , i , a i + 1 , ..., a j-1 , a j , a j + 1 , ...>
      Sequence after swap: <... a i-1 , j , a j-1 , ..., a i-1 , i , a j + 1 , ...>

  • Report (i):

    Report the i-th element in the sequence, i.e. i .

Here poly-logn means some degree of log n. how log (n) Β· log (n) may be acceptable.

[Note: thanks prof. Baswan for asking this question.]

+5
2

node, Left & Right .

  • Left, ,
  • Else ( Right), ,

Report : O(log n)

Revert , , .

, "" , ( ). [a..b] [i..j]

  • , ( )
  • Revert [a..i-1] [j+1..b]

, :/

:) , , .

, - , , .

+1

Splay trees + O (log n), . , , , O (log n) node, .

(: , , .)

0

All Articles