#K86187. Invert Parity Subarray
Invert Parity Subarray
Invert Parity Subarray
You are given an array of integers and two indices, start and end. Your task is to invert the parity of each element within the subarray from index start to end (inclusive).
The parity inversion is defined as follows:
\[ \text{if } a_i \text{ is even, then } a_i \rightarrow a_i + 1; \quad \text{if } a_i \text{ is odd, then } a_i \rightarrow a_i - 1 \]Note:
- If the indices are out of bounds, they must be clamped to the valid range \(0 \leq i \leq n-1\), where \(n\) is the length of the array.
- If start is greater than end, swap them before processing.
- If the array is empty, output an empty result.
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- An integer \(n\) representing the number of elements in the array.
- \(n\) space-separated integers representing the array elements.
- Two space-separated integers representing the indices start and end.
outputFormat
Output the modified array as space-separated integers on a single line to standard output (stdout). If the array is empty, output nothing.
## sample5
1 2 3 4 5
1 3
1 3 2 5 5