How to use Splay Tree to solve this problem?

Revision en3, by, 2016-05-23 09:03:49

My problem is: Given a sequence of integers (a_n): a_1, a_2, ..., a_n. We do Q queries, each of them (l, r) requires reverse elements from a_l to a_r.

For example, Given a sequence: 2, 3, 4, 5. The query (1, 3) changes the sequence into 4, 3, 2, 5.

After performing Q queries, the problem asks us to print out the modified sequence.

How to solve this problem, if n and Q are large integers (such as 10^5)?

I hear that the solution uses an approach of Splay Tree.

Please help me and thank you.

Tags splay tree


  Rev. Lang. By When Δ Comment
en3 English 2016-05-23 09:03:49 1 Tiny change: 'or examples,\nGiven a' -> 'or example,\nGiven a'
en2 English 2016-05-23 08:59:01 13
en1 English 2016-05-23 08:57:58 551 Initial revision (published)