#K80507. Sequence Operation Queries
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:
- An integer \( n \) representing the length of the sequences.
- A string \( X \) of length \( n \) consisting only of the characters A, B, C, and D.
- A string \( Y \) of length \( n \) consisting only of the characters A, B, C, and D.
- An integer \( q \) indicating the number of operations to perform.
- \( 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.
5
AACBD
BDCAB
4
Query 3 3 A
Swap 1 5
Query 5 5 D
Swap 2 4
2
8
</p>