A persistent data structure is a data structure in which you can modify and access any previous version of the data structure. The kth query will create version k of the data structure. Your task is to implement a persistent deque, each query copies an old version of the structure and then modifies it. You need to process the following queries:
All queries are online, that means you should flush the output before reading the input for the following query. Use fflush(stdout) for C/C++.
In the first line an integer Q, the number of queries. Each of the next Q lines has a query, in the format given in the statement.
Limits
For each query of type < or >, print the element removed.
Remember to flush the output after every answer.
8
B 0 10
E 0 -10
< 2
> 1
E 2 5
> 5
< 6
< 2
-10
10
5
-10
-10
You should implement a list that allows the following operations:
Initially, the list is empty.
All queries are online, that means you should flush the output before reading the input for the following query. Use fflush(stdout) for C/C++.
In the first line an integer Q, the number of queries. Each of the next Q lines has a query, in the format given in the statement.
Limits
For each query of type O, print YES or NO, the value returned. Don't forget to flush the output.
5
< 1
< 2
O 1 2
I 2 10
O 10 1
NO
YES
10
< 1
I 1 2
I 1 3
I 1 4
I 1 5
I 1 6
I 1 7
O 7 6
O 3 7
O 6 4
YES
NO
YES
Your task is to implement a retroactive queue.
A data structure is retroactive if it allows insertion and removal of operations in the past, and also queries. Informally, is like you went to the past, changed the structure, and the change propagated to the present (like some bad fiction movie).
An usual queue should support modifications enqueue(x), that adds the element x to the end of the queue, and dequeue(), that removes the first element of the queue.
You must deal with the following queries:
All queries are online, that means you should flush the output before reading the input for the following query. Use fflush(stdout) for C/C++.
On the first line, a single integer Q, the number of queries.
Each of the next Q lines have a query, in the format given in the statement.
Limits
For each Q t k query, print its answer.
5
+ 1 E 1
+ 2 E 2
Q 2 1
- 1
Q 2 1
1
2
11
+ 10 E 10
+ 200 E 5
Q 201 1
+ 5 E 1
Q 201 1
+ 7 D
Q 201 2
- 7
Q 199 1
Q 200 2
Q 201 3
10
1
5
1
10
5
On the first sample, 1 and 2 are added to the queue, and then the insertion of 1 is removed.