#K80507. Sequence Operation Queries

    ID: 35545 Type: Default 1000ms 256MiB

Sequence Operation Queries

Sequence Operation Queries

Sequence Operation Queries

You are given two sequences of uppercase letters that represent economic sectors. Each letter has a value: \(A = 1\), \(B = 2\), \(C = 3\), and \(D = 4\). You must perform a series of operations on these sequences. There are two types of operations:

  • Swap i j: Swap the characters at the i-th and j-th positions in both sequences (1-indexed).
  • Query n m k: Consider the first n characters of the first sequence and the first m characters of the second sequence. Count the occurrences of the letter k in both prefixes. The result is computed as follows:
    \( \text{Result} = (\text{count in first prefix} + \text{count in second prefix}) \times v(k) \) where \(v(k)\) is the value assigned to letter k.

Output each query result on a new line in the order the queries appear.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer \( n \) representing the length of the sequences.
  2. A string \( X \) of length \( n \) consisting only of the characters A, B, C, and D.
  3. A string \( Y \) of length \( n \) consisting only of the characters A, B, C, and D.
  4. An integer \( q \) indicating the number of operations to perform.
  5. \( q \) lines follow, each describing an operation in one of the following formats:
    • Swap i j
    • Query n m k

outputFormat

For each Query operation, output a single integer representing the computed result on a new line. If there are no Query operations, output nothing.

## sample
5
AACBD
BDCAB
4
Query 3 3 A
Swap 1 5
Query 5 5 D
Swap 2 4
2

8

</p>