Deque 2
Time limit2sMemory limit1024 MB
The task is to implement a deque with eight command types (push front/back, pop front/back, size, empty, front, back) and print results for queries.
- Level
Easy2 of 10
- Topics
- Queue, Simulation
- Solved
- No attempts yet
Problem
Implement a deque that stores integers, then write a program that processes the commands given as input.
There are eight kinds of commands.
1 X: Inserts the integerXat the front of the deque. (1 ≤X≤ 100,000)2 X: Inserts the integerXat the back of the deque. (1 ≤X≤ 100,000)3: If the deque has an integer, removes the front integer and prints it. Otherwise, prints-1.4: If the deque has an integer, removes the back integer and prints it. Otherwise, prints-1.5: Prints the number of integers in the deque.6: Prints1if the deque is empty, otherwise0.7: If the deque has an integer, prints the front integer. Otherwise, prints-1.8: If the deque has an integer, prints the back integer. Otherwise, prints-1.
Input
The first line contains the number of commands N. (1 ≤ N ≤ 1,000,000)
Each of the following N lines contains one command.
At least one command asks for output.
Output
For each command that asks for output, print the result on its own line.