Problem p01877 - Generation 1

Orig Description

F: Precisely - Kitsuchiri -
Problem
Chisato Atsuji, a second-year student in the Wakakamatsu High School Class 2-H, can't be satisfied unless the sequence is "precisely" arranged.
According to Atsuji, a "precisely" arranged sequence is a sequence that is even in length and symmetrical from left to right.
That is, for a sequence S of length N (N is even), the sequence S is "precisely" arranged if it satisfies the following conditions.
S_1 = S_N, S_2 = S_{N-1}, ..., S_{N/2} = S_{N - N/2 + 1}
The math teacher in charge of the second year's class has been struggling to make the sequence "precisely" arranged by applying many queries to add a number x to each element from the l-th to the r-th of the sequence.
Your job as a genius programmer belonging to the second year's class is to create a program that checks whether the sequence being rebuilt by the teacher is "precisely" arranged before the teacher becomes hopeless.
Input format
The input consists of the following format.
N
S_1 ... S_N
Q
q_1
...
q_Q
Q is the total number of queries, and for each i (1 ≤ i ≤ Q), each q_i gives l, r, and x in order, separated by a single half-width space.
Also, the following constraints are satisfied.
2 ≤ N ≤ 500,000.
N is even.
For 1 ≤ j ≤ N, -100,000,000 ≤ S_j ≤ 100,000,000.
Each element T_{i,j} of the sequence after applying each i-th query satisfies -100,000,000 ≤ T_{i,j} ≤ 100,000,000.
1 ≤ Q ≤ 100,000.
1 ≤ l ≤ r ≤ N.
-1,000 ≤ x ≤ 1,000.
Output format
If the sequence after processing query i is "precisely" arranged, output "1" on the i-th line; otherwise, output "0".
Sample Input 1
10
0 1 2 3 4 4 3 2 1 0
7
2 6 0
2 4 5
7 9 10
2 4 5
3 8 100
4 6 1000
7 7 1000
Sample Output 1
1
0
0
1
1
0
1
Sample Input 2
10
4 4 4 4 4 4 4 4 6 4
5
9 9 -2
1 10 1000
1 10 -1000
3 8 100
5 6 1
Sample Output 2
1
1
1
1
1

Extracted Specification

An integer N (2 ≤ N ≤ 500,000), representing some quantity or size, and it is even.
A list of integers S of size N, where each integer is between -100,000,000 and 100,000,000.
An integer Q (1 ≤ Q ≤ 100,000), representing the number of queries.
Q queries, each containing three integers (l, r, x) where 1 ≤ l ≤ r ≤ N and -1,000 ≤ x ≤ 1,000.

### Example Input:

```
10
0 1 2 3 4 4 3 2 1 0
7
2 6 0
2 4 5
7 9 10
2 4 5
3 8 100
4 6 1000
7 7 1000
```

### Function Signature:
Write a function f(N, S, Q, queries) that takes in the input.
def f(N: int, S: List[int], Q: int, queries: List[Tuple[int, int, int]]):
    '''
    N: an integer
    S: a list of integers
    Q: an integer
    queries: a list of tuples, each containing three integers
    '''

Test Case Generator

Sure! Below is a test case generator for the problem statement you provided:

```python
import random

def tcgen():
    # Generate N, ensuring it's even and within the specified range
    N = random.randint(1, 250000) * 2  # Since N needs to be even and between 2 and 500,000
    
    # Generate the sequence S with elements within the specified range
    S = [random.randint(-100000000, 100000000) for _ in range(N)]
    
    # Generate Q, the number of queries
    Q = random.randint(1, 100000)
    
    queries = []
    
    for _ in range(Q):
        l = random.randint(1, N)
        r = random.randint(l, N)
        x = random.randint(-1000, 1000)
        queries.append((l, r, x))
    
    # Format the output as required by the problem statement
    input_data = f"{N}\n" + " ".join(map(str, S)) + f"\n{Q}\n"
    input_data += "\n".join(f"{l} {r} {x}" for l, r, x in queries)
    
    return input_data

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

This test case generator creates:
1. An even integer `N`, between 2 and 500,000.
2. A sequence `S` of length `N` with integers between -100,000,000 and 100,000,000.
3. A number of queries `Q`, between 1 and 100,000.
4. For each query, values of `l`, `r`, and `x` within the specified ranges.

The output is formatted as required by the input format of the problem statement. This generator can be used to produce robust and varied test cases for the problem.

Extract Arguments

def extract_arguments(fh):
    N = int(fh.readline().strip())
    S = list(map(int, fh.readline().strip().split()))
    Q = int(fh.readline().strip())
    queries = []
    for _ in range(Q):
        l, r, x = map(int, fh.readline().strip().split())
        queries.append((l, r, x))
    return N, S, Q, queries