Problem p02348 - Generation 3

Orig Description

Range Update Query (RUQ)
Write a program which manipulates a sequence A = {a0, a1, . . .  , an−1} with the following operations:
update(s, t, x): change as, as+1, ..., at to x.
find(i): output the value of ai.
Note that the initial values of ai (i = 0, 1, . . .  , n−1) are  231-1.
Input
n q
query1
query2
:
queryq
  In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:
0 s t x 
  or
1 i
  The first digit represents the type of the query. '0' denotes update(s, t, x) and '1' denotes find(i).
Output
For each find operation, print the value.
Constraints
1 ≤ n ≤ 100000
1 ≤ q ≤ 100000
0 ≤ s ≤ t < n
0 ≤ i < n
0 ≤ x < 231−1
Sample Input 1
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
Sample Output 1
1
3
Sample Input 2
1 3
1 0
0 0 0 5
1 0
Sample Output 2
2147483647
5

Extracted Specification

An integer n (1 ≤ n ≤ 100000), representing some quantity or size.
An integer q (1 ≤ q ≤ 100000), representing some quantity or size.
A list of q queries, where each query is in one of the following formats:
- 0 s t x, where 0 ≤ s ≤ t < n and 0 ≤ x < 231−1
- 1 i, where 0 ≤ i < n

### Example Input:

```
3 5
0 0 1 1
0 1 2 3
0 2 2 2
1 0
1 1
```

### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, int, Optional[int], Optional[int]]]):
    ''' 
    inputs: a list of tuples, where each tuple is either (0, s, t, x) or (1, i)
    '''

Test Case Generator

Sure, I'll help you write a test case generator for the "Range Update Query (RUQ)" problem. Here’s the code:

```python
import random

def tcgen():
    # Constraints
    MAX_N = 100000
    MAX_Q = 100000
    MAX_X = 2**31 - 1

    # Generate random n and q within the constraints
    n = random.randint(1, MAX_N)
    q = random.randint(1, MAX_Q)

    # Initialize list of queries
    queries = []

    for _ in range(q):
        query_type = random.choice([0, 1])
        if query_type == 0:
            s = random.randint(0, n - 1)
            t = random.randint(s, n - 1)
            x = random.randint(0, MAX_X)
            queries.append(f"0 {s} {t} {x}")
        else:
            i = random.randint(0, n - 1)
            queries.append(f"1 {i}")

    # First line is n and q
    input_data = f"{n} {q}\n" + "\n".join(queries)
    return input_data

# Example usage:
print(tcgen())
```

### Explanation:
1. **Constraints Definitions**:
    - `MAX_N` is the maximum number of elements in the sequence `A`.
    - `MAX_Q` is the maximum number of queries.
    - `MAX_X` is the maximum value for `x`, which is \(2^{31} - 1\).

2. **Random Generators**:
    - `n` is randomly chosen between 1 and `MAX_N`.
    - `q` is randomly chosen between 1 and `MAX_Q`.

3. **Query Generation**:
    - For each query, randomly decide the query type (`0` for update and `1` for find).
    - If the query is `0`, randomly generate `s`, `t`, and `x` according to the constraints.
    - If the query is `1`, randomly generate `i` according to the constraints.

4. **Output Formatting**:
    - The first line contains `n` and `q`.
    - The following lines are the generated queries.

The `tcgen` function returns a string representing the input data of the problem. You can use this function to generate various test cases for your competitive programming problem.

Extract Arguments

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

# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh:
#         n, q, queries = extract_arguments(fh)
#         f(n, q, queries)