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 one of the following two types:
1. Three integers: 0, s, t, x, with constraints 0 ≤ s ≤ t < n, 0 ≤ x < 2^31−1.
2. Two integers: 1, i, with constraint 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(n, q, queries) that takes in the input.
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 and contains either 3 or 4 integers
'''
Test Case Generator
Sure! Here's a test case generator for the "Range Update Query (RUQ)" problem. The generator will create random sequences and queries according to the given constraints.
```python
import random
def tcgen():
# Constraints
max_n = 100000
max_q = 100000
max_val = 2**31 - 1
n = random.randint(1, max_n)
q = random.randint(1, max_q)
queries = []
for _ in range(q):
query_type = random.choice([0, 1])
if query_type == 0: # update(s, t, x) query
s = random.randint(0, n - 1)
t = random.randint(s, n - 1)
x = random.randint(0, max_val)
queries.append(f"0 {s} {t} {x}")
else: # find(i) query
i = random.randint(0, n - 1)
queries.append(f"1 {i}")
return n, q, queries
# Example usage
n, q, queries = tcgen()
print(n, q)
for query in queries:
print(query)
```
This script generates random values for `n` (number of elements in the sequence) and `q` (number of queries) within their respective constraints. For each query, it randomly decides between an update (`0 s t x`) or a find (`1 i`) operation, ensuring that all indices and values are within the specified ranges. The output is formatted according to the problem statement.
Extract Arguments
def extract_arguments(fh):
n, q = map(int, fh.readline().strip().split())
queries = []
for _ in range(q):
query = fh.readline().strip().split()
query[0] = int(query[0])
if query[0] == 0:
query[1:] = map(int, query[1:])
else:
query[1] = int(query[1])
queries.append(tuple(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)
# for query in queries:
# print(query)