#P11040. 【MX-X3-T7】「RiOI-4」Re:End of a Dream

    ID: 11734 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>线段树平衡树O2优化组合数学梦熊比赛

【MX-X3-T7】「RiOI-4」Re:End of a Dream

Background

Original link: https://oier.team/problems/X3H


(The picture is from the Phigros song illustration. Please contact for removal if infringed.)

Let us talk about something real.

Classmates around Xiao \iiint got Ag in NOI, won awards in APIO, and did better than Xiao \iiint in NOI Qualifier and such. Xiao \iiint said he spent his time on games. But look at the neighbor who was admitted to high school early—there is already a Super Ant Egg in their florr account. Xiao \iiint said his internet was bad, so he could not perform well. But look again at the i wanna masters next door—they have already started speedrunning i wanna be the guy. Xiao \iiint argued that he had not played games for long, and he was focusing on academic subjects. But when grades came out, he became the bottom of the competitive programming class. Xiao \iiint then said maybe he spent time socializing. Everyone thought he was funny, because he did not have a single friend in the class.

Xiao \iiint did not understand why it turned out like this.

This year, for Xiao \iiint, might be the last year of his OI career. One year is too short—how much can be fixed? how much can be saved? When he first learned OI, he secretly made up his mind to become a "legendary top contestant" in everyone's eyes. Three years passed, and the future was still completely dark.

This might be $\color{#CD0000}\overset{\text{End of a Dream}}{\text{the end of a dream}}$.

Maybe, dreams run in reverse.

...

But this is a Dream Bear weekly contest problem, not a place for the problemsetter to write nonsense, so Xiao \iiint needs you to solve a counting problem.

Problem Description

Given n,qn, q. There is an integer mm initially equal to 00. You need to support the following operations:

  • 0 x: add 2x2^x to mm.
  • 1 x: subtract 2x2^x from mm. If m<2xm < 2^x, ignore this operation.
  • 2: query how many strictly increasing positive integer sequences of length nn, where each number is in 1m1 \sim m, satisfy that both the prefix XOR sums and the suffix XOR sums are strictly increasing. Output the answer modulo 998244353998\,244\,353.

Here, for a sequence a1,a2,,ana_1, a_2, \cdots, a_n, its prefix XOR sums refer to a sequence s1,s2,,sns_1, s_2, \cdots, s_n, where

$$s_i=\begin{cases} a_1&i=1\\ a_{i}\oplus s_{i-1}&i\ge2 \end{cases}$$

and its suffix XOR sums refer to a sequence t1,t2,,tnt_1, t_2, \cdots, t_n, where

$$t_i=\begin{cases} a_n&i=1\\ a_{n-i+1}\oplus t_{i-1}&i\ge2 \end{cases}$$

where xyx \oplus y denotes the bitwise XOR of xx and yy.

Input Format

The first line contains two positive integers, denoting n,qn, q.

The next qq lines each describe one operation.

Output Format

For each 2 operation, output the corresponding answer modulo 998244353998\,244\,353.

3 4
0 0
0 1
0 2
2
2
20 15
0 1
0 2
0 21
0 5
2
0 15
1 18
0 7
0 8
0 25
2
1 22
0 12
0 13
2
313288290
39181640
134388812

Hint

Sample Explanation #1

When querying, m=7m = 7. The sequences that satisfy the requirements are {1,2,4}\{1,2,4\} and {1,3,5}\{1,3,5\}. It can be proven that no other solutions exist.

Note that the sequence {1,3,1}\{1,3,1\} does not satisfy the requirements. Although both its prefix and suffix XOR sums are strictly increasing sequences {1,2,3}\{1,2,3\}, the sequence itself does not satisfy the strictly increasing constraint.

Constraints

This problem uses bundled testdata.

Subtask Score nn\le qq\le xx\le Special property
11 55 1010
22 1010 10310^3 10310^3
33 1111 2×1052\times10^5 10510^5 AB
44 1414 10510^5
55 1616 10710^7 10210^2 10710^7 B
66 1919 2×1052\times10^5
77 2525

Special property A: only the last operation is a 2 operation.
Special property B: does not contain 1 operations.

For 100%100\% of the data, 3n1073 \le n \le 10^7, 1q2×1051 \le q \le 2\times 10^5, 0x1070 \le x \le 10^7.

Translated by ChatGPT 5