#K85022. String Query Processor

    ID: 36549 Type: Default 1000ms 256MiB

String Query Processor

String Query Processor

You are given a string of length \(N\) and a sequence of queries to process on the string. The queries may ask you to reverse a substring, replace a character at a given position, or count the occurrences of a given character in a specified substring.

Operations:

  • REV l r: Reverse the substring from index \(l\) to index \(r\) (1-indexed).
  • REP u c: Replace the character at position \(u\) (1-indexed) with character \(c\).
  • COUNT c l r: Count the number of times character \(c\) appears in the substring from index \(l\) to index \(r\) (1-indexed).

After processing all queries, output the results of all COUNT queries in the order they appeared; if there are no COUNT queries, print nothing.

Note: All indices are 1-indexed.

inputFormat

The input is given through stdin in the following format:

N
S
Q
query1
query2
... 
queryQ

Where:

  • N is an integer representing the length of the string.
  • S is the initial string of length \(N\).
  • Q is the number of queries.
  • Each of the next \(Q\) lines contains a query in one of the three formats described above.

outputFormat

For each COUNT query, output the result on a separate line to stdout. If there are no COUNT queries, the program should not output anything.

## sample
5
abcde
4
COUNT a 1 5
REV 2 4
COUNT b 1 5
REP 3 z
1

1

</p>