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 even quantity or size.
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 query consisting of three integers l, r, and 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 given problem statement "Precisely - Kitsuchiri":
```python
import random
def tcgen():
# Ensure N is even
N = random.randint(1, 250000) * 2
# Generate random array S with values between -100000000 and 100000000
S = [random.randint(-100000000, 100000000) for _ in range(N)]
# Number of queries Q
Q = random.randint(1, 100000)
# Generate Q queries, each with l, r, and x
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))
return N, S, Q, queries
def print_test_case(N, S, Q, queries):
print(N)
print(' '.join(map(str, S)))
print(Q)
for query in queries:
print(' '.join(map(str, query)))
# Generate a test case
N, S, Q, queries = tcgen()
print_test_case(N, S, Q, queries)
```
This script will generate a random test case for the problem statement you provided. Here's a brief explanation of each part:
1. **N**: Generate an even number between 2 and 500,000.
2. **S**: Generate an array of `N` integers, where each integer is between -100,000,000 and 100,000,000.
3. **Q**: Generate a random number of queries between 1 and 100,000.
4. **Queries**: For each query, generate random values for `l` (start index), `r` (end index), and `x` (value to add), ensuring that `l ≤ r` and `1 ≤ l, r ≤ N`. The value `x` is between -1000 and 1000.
The `print_test_case` function prints the generated test case in the specified format.
You can run the script to generate and print a new test case each time. This will help you create diverse test cases for thorough testing of your solution for the problem "Precisely - Kitsuchiri".
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
# Example of usage:
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, S, Q, queries = extract_arguments(fh)
# f(N, S, Q, queries)