Problem p02436 - Generation 1

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 some quantity or size.
A list of q queries, each query being either:
- Two integers `0 t x`, where -1,000,000,000 ≤ x ≤ 1,000,000,000.
- One integer `1 t`.
- One integer `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, ...]]):
    ''' 
    n: an integer 
    q: an integer 
    queries: a list of tuples, where each tuple represents a query
    '''
```

Test Case Generator

Sure, I'll write a test case generator for the "Queue" problem statement. This generator will create a random number of queues and perform a random sequence of operations on them, following the given constraints.

Here's the implementation:

```python
import random

def tcgen():
    # Number of queues (1 ≤ n ≤ 1,000)
    n = random.randint(1, 1000)
    
    # Number of queries (1 ≤ q ≤ 200,000)
    q = random.randint(1, 200000)
    
    queries = []
    
    for _ in range(q):
        operation = random.randint(0, 2)
        t = random.randint(0, n-1)
        
        if operation == 0:
            # enqueue operation
            x = random.randint(-1000000000, 1000000000)
            queries.append(f"0 {t} {x}")
        else:
            # front or dequeue operation
            queries.append(f"{operation} {t}")
    
    return n, q, queries

# Example usage:
n, q, queries = tcgen()

print(n, q)
for query in queries:
    print(query)
```

The `tcgen` function generates:

1. A random number of queues \( n \) within the range [1, 1000].
2. A random number of queries \( q \) within the range [1, 200000].
3. A sequence of \( q \) operations:
   - Enqueue operations (0 \( t \) \( x \)) with a random queue index \( t \) and a random integer \( x \) within the range [-1,000,000,000, 1,000,000,000].
   - Front operations (1 \( t \)) with a random queue index \( t \).
   - Dequeue operations (2 \( t \)) with a random queue index \( t \).

This will ensure that the generated test cases cover a wide range of possible scenarios within the given constraints.

Extract Arguments

def extract_arguments(fh):
    n, q = map(int, fh.readline().strip().split())
    queries = []
    for _ in range(q):
        queries.append(tuple(map(int, fh.readline().strip().split())))
    return n, q, queries