#P7119. Mivik 的游戏

Mivik 的游戏

Description

Mivik first places nn coins in a row. Some are face up and the rest are face down. W!ʌ!k plans to repeatedly perform the following operation until none of the nn coins is face down:

  • If there are currently kk coins that are face down among the nn coins, then flip the kk-th coin from left to right. Specifically, if the kk-th coin from left to right is face up, change it to face down; if it is face down, change it to face up.

Before W!ʌ!k starts playing, Mivik wants to test W!ʌ!k. Mivik wants W!ʌ!k to compute how many such operations he will perform in total, or whether W!ʌ!k will never be able to stop performing operations.

W!ʌ!k solved this problem quickly, but Mivik, whose mindset is even more twisted than yky's, obviously would not let him off. Mivik performs many flips: each time, he flips an interval of coins, and he requires W!ʌ!k to compute how many such operations W!ʌ!k will perform in total, or whether W!ʌ!k will never be able to stop performing operations.

Note that W!ʌ!k only needs to compute how many operations will be performed in total, and will not actually perform the operations.

Input Format

The input has (m+2)\left(m+2\right) lines.

The first line contains two non-negative integers n,mn,m, where nn is the number of Mivik's coins, and mm is the number of interval-flip operations performed by Mivik.

The second line is a string consisting only of H\texttt H and T\texttt T. If the ii-th character sis_i is H\texttt H, it means the ii-th coin from left to right is initially face up; if sis_i is T\texttt T, it means the ii-th coin from left to right is initially face down.

The next mm lines each contain two positive integers li,ril_i,r_i, meaning Mivik flipped the coins from positions lil_i to rir_i (inclusive) from left to right.

Output Format

Output (m+1)\left(m+1\right) lines. They represent, at the (m+1)\left(m+1\right) moments (before actually performing any of Mivik's flips, and after each of the mm flips), how many such operations W!ʌ!k would perform in total if he starts at that moment, or whether W!ʌ!k will never be able to stop performing operations. If at some moment W!ʌ!k cannot stop performing operations, output the string never\texttt{never} on the corresponding line.

2 2
TT
2 2
1 2

2
1
3

5 0
HTHTH

8

10 10
HTHHTHTHHH
9 9
5 5
10 10
7 7
6 6
9 9
4 4
9 9
7 7
2 2

19
30
27
40
33
38
27
28
37
40
47

Hint

Sample Explanation #1

Initially, both coins are face down, so if W!ʌ!k starts performing operations from this moment, he will flip coin 22. After that, only one coin is face down, so the second operation will flip coin 11. After the second operation, no coin is face down, so W!ʌ!k will not perform any more operations, and he will perform 22 operations in total.

Sample Explanation #2

These 88 operations flip coins 2,1,2,3,4,3,2,12,1,2,3,4,3,2,1, respectively.

Test Point Constraints

This problem uses bundled tests.

For all data, 1n,m1061\le n,m\le10^6, si{H,T}s_i\in\left\{\texttt H,\texttt T\right\}, 1lirin1\le l_i\le r_i\le n.

The specific limits for each subtask are shown in the table below:

Subtask ID Score Special Constraints
1 10 n3n\le3
2 20 n,m100n,m\le100
3 30 m10m\le10
4 20 li=ril_i=r_i
5 None.

The input and output size of this problem is large, so please use fast I/O.

Translated by ChatGPT 5