Keyboard

AtCoder
IDabc434_g
Time3000ms
Memory256MB
Difficulty
For a string $A$ consisting of `1`, `2`, $\dots$, `9` and `B`, define $f(A)$ as the string obtained by the following procedure: * Initially, there is an empty string $C$. * Perform the following operations in the order $i = 1, 2, \dots, |A|$: * If $A_i$ is one of `1`, `2`, $\dots$, `9`, append $A_i$ to the end of $C$. * If $A_i =$ `B`, delete the last character of $C$. However, if $C$ is an empty string, do nothing. * Let $f(A)$ be $C$ after completing all the above operations. You are given a string $S$ of length $N$ consisting of `1`, `2`, $\dots$, `9`, and `B`. Process $Q$ queries described below. Each query is of one of the following two types: * $1\ \ x\ \ c$ : Update $S_x$ to $c$. (Here, $c$ is `1`, `2`, $\dots$, `9`, or `B`.) * $2\ \ l\ \ r$ : Let $T$ be the string formed by extracting the $l$\-th through $r$\-th characters of $S$. Then, let $U=f(T)$. If $U$ is an empty string, output $-1$; otherwise, output the remainder when the value of $U$ regarded as a decimal integer is divided by $998244353$. ## Constraints * $1 \leq N \leq 8 \times 10^6$ * $1 \leq Q \leq 2 \times 10^5$ * $S$ is a string of length $N$ consisting of `1`, `2`, $\dots$, `9`, and `B`. * $1 \leq x \leq N$ * $c$ is `1`, `2`, $\dots$, `9`, or `B`. * $1 \leq l \leq r \leq N$ * $N, Q, x, l, r$ are integers. ## Input The input is given from Standard Input in the following format, where $\mathrm{query}_i$ denotes the $i$\-th query. $N$ $Q$ $S$ $\mathrm{query}_1$ $\mathrm{query}_2$ $\vdots$ $\mathrm{query}_Q$ Each query is given in one of the following two formats: $1$ $x$ $c$ $2$ $l$ $r$ [samples]
Samples
Input #1
10 12
1234567891
2 5 7
2 2 8
2 1 10
1 3 B
1 4 B
2 2 4
2 2 8
2 1 10
1 7 B
2 3 9
1 3 4
2 1 10
Output #1
567
2345678
236323538
-1
5678
567891
589
125891

For the first query, $T=U=$ `567`. Thus, output $567$.  
For the third query, $T=U=$ `1234567891`. Thus, output $1234567891 \bmod 998244353 = 236323538$.  
For the sixth query, $T=$ `2BB` and $U$ is an empty string. Thus, output $-1$.
API Response (JSON)
{
  "problem": {
    "name": "Keyboard",
    "description": {
      "content": "For a string $A$ consisting of `1`, `2`, $\\dots$, `9` and `B`, define $f(A)$ as the string obtained by the following procedure: *   Initially, there is an empty string $C$. *   Perform the following ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc434_g"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For a string $A$ consisting of `1`, `2`, $\\dots$, `9` and `B`, define $f(A)$ as the string obtained by the following procedure:\n\n*   Initially, there is an empty string $C$.\n*   Perform the following ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments