Orig Description
Queue
Queue is a container of elements that are inserted and deleted according to FIFO (First In First Out).
For $n$ queues $Q_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations.
enqueue($t$, $x$): Insert an integer $x$ to $Q_t$.
front($t$): Report the value which should be deleted next from $Q_t$. If $Q_t$ is empty, do nothing.
dequeue($t$): Delete an element from $Q_t$. If $Q_t$ is empty, do nothing.
In the initial state, all queues are empty.
Input
The input is given in the following format.
$n \; q$
$query_1$
$query_2$
:
$query_q$
Each query $query_i$ is given by
0 $t$ $x$
or
1 $t$
or
2 $t$
where the first digits 0, 1 and 2 represent enqueue, front and dequeue operations respectively.
Output
For each front operation, print an integer in a line.
Constraints
$1 \leq n \leq 1,000$
$1 \leq q \leq 200,000$
$-1,000,000,000 \leq x \leq 1,000,000,000$
Sample Input 1
3 9
0 0 1
0 0 2
0 0 3
0 2 4
0 2 5
1 0
1 2
2 0
1 0
Sample Output 1
1
4
2
Extracted Specification
An integer n (1 ≤ n ≤ 1,000), representing some quantity or size.
An integer q (1 ≤ q ≤ 200,000), representing another quantity or size.
A list of q queries, where each query is one of the following types:
1. A tuple (0, t, x) where -1,000,000,000 ≤ x ≤ 1,000,000,000.
2. A tuple (1, t).
3. A tuple (2, t).
### Example Input:
```
3 9
0 0 1
0 0 2
0 0 3
0 2 4
0 2 5
1 0
1 2
2 0
1 0
```
### Function Signature:
Write a function f(n, q, queries) that takes in the input.
```python
def f(n: int, q: int, queries: List[Tuple[int, int, int]]):
'''
n: an integer
q: an integer
queries: a list of tuples
'''
Test Case Generator
Sure, I'll write a test case generator for your problem statement. The generator will create random test cases that conform to the specified constraints.
Here is the Python code for the test case generator:
```python
import random
def generate_test_case():
# Number of queues
n = random.randint(1, 1000)
# Number of queries
q = random.randint(1, 200000)
# List to store queries
queries = []
for _ in range(q):
# Randomly choose a query type: 0, 1, or 2
query_type = random.randint(0, 2)
# Choose a queue index between 0 and n-1
t = random.randint(0, n - 1)
if query_type == 0: # enqueue operation
# Random integer x in the specified range
x = random.randint(-1000000000, 1000000000)
queries.append(f"0 {t} {x}")
elif query_type == 1 or query_type == 2: # front or dequeue operation
queries.append(f"{query_type} {t}")
return n, q, queries
# Function to print the test case in the required format
def print_test_case():
n, q, queries = generate_test_case()
print(f"{n} {q}")
for query in queries:
print(query)
# Example usage
print_test_case()
```
The `generate_test_case` function creates a random number of queues `n` and a random number of queries `q`. It then generates each query based on the specified format:
- For enqueue operations, it generates a query with `0 t x`, where `t` is the queue index and `x` is a random integer.
- For front and dequeue operations, it generates queries with `1 t` and `2 t` respectively, where `t` is the queue index.
The `print_test_case` function prints the generated test case in the required input format.
You can call the `print_test_case` function to generate and print a random test case for the problem. This should help in testing and debugging your solution for various scenarios.
Extract Arguments
def extract_arguments(fh):
n, q = map(int, fh.readline().strip().split())
queries = []
for _ in range(q):
query = list(map(int, fh.readline().strip().split()))
queries.append(tuple(query))
return n, q, queries