I am trying to solve this problem :
https://www.spoj.pl/problems/CERC07S/
I have identified that i need a datastructure in which reversing operations have lesser time complexity. I tried to create one using a doubly linked list, in which (i thought) reversing can be done in O(1) by just changing a value associated with the starting and ending node which indicates the direction of traversing the list. I tried to implement it but got stuck. Maybe the approach is wrong!
Are trees applicable here? If yes, how? Any ideas or links are appreciated?
Thanks in advance.