I need help with choosing right data structure to my exercise.
For input I have been given number of operations that should be executed(t) and after that indexed sequence of natural numbers seperated with a space. So for example:
3 1 2 3
This means that there will be 3 operations executed on sequence {1,2,3}.
There is also defined a pointer, which shows current position. Operations on that sequence that I should implement are:
R -> removing element c on index PTR+1 and moving PTR forward c times
X -> inserting right after element c, which is on index PTR (so inserting on PTR+1), element with value of c-1 and of course moving PTR forward c times.
My job is to find ending sequence after performing operations R and X t times so that if its element is even then do the R, else do the X. At the start PTR shows first element(if exists) and it should be all in cycle.
For given example at the start of post the output should be:
0 0 3 1
I know that it might sound confusing, so let me show you how this should work step by step.
t = 1
Starting sequence: 1 2 3
Actual position: PTR -> 1
Operation: X, c=1
Ending sequence: 1 0 2 3
Ending position: PTR -> 0
t = 2
Starting sequence: 1 0 2 3
Actual position: PTR -> 0
Operation: R, c=2
Ending sequence: 1 0 3
Ending position: PTR -> 1
t = 3
Starting sequence: 1 0 3
Actual position: PTR -> 1
Operation: X, c=1
Ending sequence: 1 0 0 3
Ending position: PTR -> 0
The solution is a sequence from PTR in right direction. So output should be: 0 0 3 1
As for circumscriptions:
starting length of C sequence up to 10^7
number of t operations up to 10^7
moving PTR to right up to 10^9 times
I have created my algorithm, which is based on circular linked list. Works, but it's too slow for some tests. I'd be more than grateful if someone could help me in finding the best data structure.
I've got also a hint from my teacher that I should use binary list, but to be honest I didn't find anything about this structure on the internet! Maybe also someone knows this thing and show me where can I search for information about it? I'd apreciate any help.