#abc298d. D - Writing a Numeral

D - Writing a Numeral

Score : 400400 points

问题描述

我们有一个字符串 SS。初始时,S=S= 1

按照以下格式顺序处理 QQ 个查询操作:

  • 1 x:在 SS 的末尾追加一个数字 xx
  • 2:删除 SS 开头的数字。
  • 3:计算以 SS 表示的十进制数对 998244353998244353 取模的结果,并打印该数值。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a string SS. Initially, S=S= 1.
Process QQ queries in the following formats in order.

  • 1 x : Append a digit xx at the end of SS.
  • 2 : Delete the digit at the beginning of SS.
  • 3 : Print the number represented by SS in decimal, modulo 998244353998244353.

Constraints

  • 1Q6×1051 \leq Q \leq 6 \times 10^5
  • For each query in the first format, x{1,2,3,4,5,6,7,8,9}x \in \{1,2,3,4,5,6,7,8,9\}.
  • A query in the second format is given only if SS has a length of 22 or greater.
  • There is at least one query in the third format.

Input

The input is given from Standard Input in the following format:

QQ

query1\mathrm{query}_1

\vdots

queryQ\mathrm{query}_Q

Here, queryi\mathrm{query}_i denotes the ii-th query, which is in one of the following formats:

11 xx

22

33

Output

Print qq lines, where qq is the number of queries in the third format. The ii-th line (1iq)(1 \leq i \leq q) should correspond to the ii-th query in the third format.

Sample Input 1

3
3
1 2
3

Sample Output 1

1
12

In the first query, SS is 1, so you should print 11 modulo 998244353998244353, that is, 11.
In the second query, SS becomes 12.
In the third query, SS is 12, so you should print 1212 modulo 998244353998244353, that is, 1212.

Sample Input 2

3
1 5
2
3

Sample Output 2

5

Sample Input 3

11
1 9
1 9
1 8
1 2
1 4
1 4
1 3
1 5
1 3
2
3

Sample Output 3

0

Be sure to print numbers modulo 998244353998244353.

update @ 2024/3/10 12:22:06