Which approach for "longest valid sequence in range" query ?

Revision en4, by CleanAirAndCleanWater, 2015-08-04 05:39:22

Hi all,

I have been struggling with this problem for a long time, that would be really helpful if you could give me some hints :)

Given an array A of N elements integer number. N can be up to 200000. Each element A[i] ranges from -1e9 to 1e9, no element equals to Zero (0). We define a "valid" sequence such that 1. {x, -x} is valid sequence. 2. {x, S, -x} is valid sequence if S is a valid sequence. 3. {S1, S2} is valid sequence if S1, S2 are both valid sequences.

There are M queries, M can be up to 200000. Each query asks you to find the longest valid sequence in range [L, R] with 1 <= L <= R <= N.

Link to the problem: http://vn.spoj.com/VM14/problems/VMLSEQ/ (Vietnamese, my friend told me the contest is over so submission is not allowed anymore, but I think it's still very interesting/hard problem for discussion)

I came up with a hashing — based method to compute the "nearest" index j for each index i so that sequence [i, j] is valid, but I couldn't go any further. I thought the solution could be some kinds of merging — technique with two consecutive ranges in Interval tree (suffix — prefix), but so far I have no efficient method for that :(

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English CleanAirAndCleanWater 2015-08-04 05:39:22 3 Tiny change: '**\n` 1. {-x, +x} is vali' -> '**\n` 1. {x, -x} is vali'
en3 English CleanAirAndCleanWater 2015-08-03 22:28:46 27
en2 English CleanAirAndCleanWater 2015-08-03 22:26:00 6
en1 English CleanAirAndCleanWater 2015-08-03 22:23:28 1284 Initial revision (published)