#P6373. 「StOI-1」IOI 计数

「StOI-1」IOI 计数

Description

Given a string SS of length nn, perform mm operations:

Operation 1: 11 xx cc means changing the xx-th character to cc (where cc is only I or O).

Operation 2: 22 ll rr asks how many triples (i,j,k)(i,j,k) in the string SS satisfy: Si=S_{i}= I, Sj=S_{j}= O, Sk=S_{k}= I, and li<j<krl \le i < j < k \le r.

Input Format

The first line contains two positive integers nn and mm.

The next line contains a string ss of length nn, and the next mm lines contain the operations.

Their meanings are the same as described above.

Output Format

Output multiple lines: for every operation 2, output the answer to the query, with each answer on its own line.

4 3
IOOI
2 1 4
1 1 O
2 1 2
2
0
10 10
IIOOIOIIIO
1 1 I
2 1 7
1 5 O
2 5 9
1 4 I
1 10 I
2 1 10
2 5 10
2 2 8
2 3 9
11
0
34
0
11
6

Hint

Constraints:

For 2020% of the testdata: 1n,m1001 \le n,m \le 100, 1lrn1 \le l \le r \le n.

For another 2020% of the testdata: 1n1051 \le n \le 10^{5}, m=1m = 1, 1lrn1 \le l \le r \le n.

For another 2020% of the testdata: 1n,m1051 \le n,m \le 10^{5}, l=1,r=nl = 1, r = n.

For 100100% of the testdata: 1n,m5×1051 \le n,m \le 5 \times 10^{5}, 1lrn1 \le l \le r \le n.

All input is guaranteed to be valid.

Translated by ChatGPT 5