Add or Multiply

시간 제한7초메모리 제한1024 MB

요약
숫자 블록 교환과 연산자 블록 뒤집기(개별 또는 전체)가 반복될 때 수식의 값을 10^9+7로 나눈 나머지로 계속 출력한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 수학, 구현
정답자
아직 제출이 없습니다

문제

Your younger sister is playing with a wooden math toy consisting of number and operator blocks. Each number block is printed with a single digit from 11 to 99, and operator blocks are double-sided; ++ and ×\times are printed on each side.

She has just built a math expression by alternating number and operator blocks. The first block is a number, the second is an operator, the third is a number, and so on. She asks, "can you answer the value of the expression?"

Further, she repeatedly makes one of the following moves.

  • s ii jj (swap): Swaps the iith and jjth number blocks.
  • f ii (flip): Flips the iith operator block. Its operator alternates between ++ and ×\times.
  • a (all flip): Flips all the operator blocks in the entire math expression.

After her move, you have to quickly answer the updated value (possibly the same as the previous one). Remember that you must perform multiplications earlier than additions.

입력

The first line of input contains two integers NN (2≤N≤2×1052 \leq N \leq 2 \times 10^5) and MM (1≤M≤2×1051 \leq M \leq 2 \times 10^5), where NN is the number of integers and MM is the number of queries.

The second line represents the initial input of 2N−12N - 1 characters. Single digits between 11 and 99 are at odd positions, and operators ++ ("+") or ×\times ("*") are at even positions.

Each of the next MM lines represents your sister's move.

The swap move is described as "s ii jj" with 1≤i,j≤N1 \leq i, j \leq N, where ii and jj are the 1-indexed positions to swap. If i=ji=j, then no blocks are swapped.

The flip move is described as "f ii" with 1≤i≤N−11 \leq i \leq N-1, meaning your sister flips the iith operator.

Finally, the all-flip move is described as "a", without additional parameters.

출력

The first line of output should be the value of the initial expression. Then, output MM more lines, one for each move. Since values can be large, print the value modulo 109+710^9 + 7 (=1,000,000,007=1\\,000\\,000\\,007).

예제1

  1. 예제 1

    입력
    3 4
    2+3*4
    s 1 2
    a
    f 2
    a
    
    예상 출력
    14
    11
    10
    24
    9