The Locked Box

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

The password of a lockbox is determined by a sequence a_n\\{a\_n\\}. The sequence a_n\\{a\_n\\} may be constructed as follows:

  1. Initially, the length of the sequence is 2 and a_0=0a\_0 = 0a_1=1a\_1 = 1.

  2. Perform some operations on the sequence. Each operation must be one of the following two types:

    • Type W - add 1 to the last term of the sequence.
    • Type E - if the last term of the sequence is 1, then add 1 to the second-to-last term. Otherwise, subtract 1 from the last term of the sequence, and append two terms to the end of the sequence. The values of the two new terms are both 1.

The lockbox cannot check the entire sequence, so the password is set to be the value of a_n\\{a\_n\\} after transformation by function ff. The function ff is defined as follows:

f(a_0,,a_k1,a_k)={a_0,k=0 f(a_0,a_1,,a_k2,a_k1+1a_k),k1.\displaystyle f(a\_0,\dots,a\_{k-1},a\_k) = \begin{cases} a\_0, & k = 0 \\\ f\left(a\_0,a\_1,\dots,a\_{k-2},a\_{k-1}+\frac{1}{a\_k}\right), & k \ge 1. \end{cases}

You need to compute the password based on the sequence of operations. However, the sequence of operations may be updated. The updates are one of the following three types:

  • APPEND c: Append an operation of type c after the current sequence of operations (that is used to generate the sequence a_n\\{a\_n\\}). c will be either character W or E.
  • FLIP l r: Flip the operations between the ll-th operation and the rr-th operation in the current sequence of operations (the indices begin with 1, and the update will include the endpoints ll and rr). Here, flipping means switching all W to E and switching all E to W.
  • REVERSE l r: Reverse the operations between the ll-th operation and the rr-th operation, which means reverse the order of operations in this interval.

입력

The first line of the input contains two integers n,qn,q, denoting the length of the initial sequence of operations and the number of updates.

The second line contains a string of length nn consisting of upper-case letters E and W, denoting the initial sequence of operations.

For the following qq lines, each line specifies an operation. The format is defined in the problem description.

출력

The output consists of q+1q+1 lines. Each line contains two integers. The first line denotes the password corresponding to the initial sequence of operations, and the following qq lines denote the passwords after each update.

It is easy to see the password must be a positive rational number. If the password is ab\frac{a}{b} where a,b>0a,b > 0 and gcd(a,b)=1\gcd(a,b) = 1, then you need output aa and bb modulo 998,244,353998\\,244\\,353 in the corresponding line.

제한

For all test cases, 1n1051 \le n \le 10^51q1051 \le q \le 10^5.

For updates APPEND, it is guaranteed that the given c will be upper-case letter W or E.

For updates FLIP and REVERSE, it is guaranteed that 1lrL1 \le l \le r \le L where LL is the length of the current sequence.

Please notice because there are updates of type APPEND, the maximum length of the sequence of operations might be as large as 2×1052 \times 10^5.

힌트

Operationsa_n{a\_n}Password
InitialWE(0,1,1,1)(0,1,1,1)23\frac{2}{3}
After 1st updateWEE(0,1,2,1)(0,1,2,1)34\frac{3}{4}
After 2nd updateEWE(1,1,1,1)(1,1,1,1)53\frac{5}{3}
After 3rd updateEEW(2,2)(2,2)52\frac{5}{2}