#C9613. Query Sequence Operations

    ID: 53726 Type: Default 1000ms 256MiB

Query Sequence Operations

Query Sequence Operations

You are given a sequence of integers and a list of queries. Each query can be one of the three types:

  • Type 1: Reverse the subsequence from index \(L\) to \(R\) (inclusive).
  • Type 2: Replace the element at index \(L\) with the value \(X\).
  • Type 3: Compute the sum of the subsequence from index \(L\) to \(R\) (inclusive).

All indices are 1-based. The queries must be processed in the order they are given, and for each query of Type 3 you should output the computed sum.

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. An integer \(n\) representing the number of elements in the sequence.
  2. A line with \(n\) space-separated integers denoting the sequence.
  3. An integer \(q\) representing the number of queries.
  4. \(q\) lines each describing a query. The format for a query is one of the following:
    • For Type 1: 1 L R
    • For Type 2: 2 L X
    • For Type 3: 3 L R

outputFormat

For each query of Type 3, output a single line containing the sum of the specified subsequence.

## sample
5
5 3 8 1 2
5
3 1 3
1 2 4
3 1 3
2 2 10
3 1 3
16

14 23

</p>