#P9055. [集训队互测 2021] 数列重排

[集训队互测 2021] 数列重排

Background

dottle bot。

Problem Description

Define the mex\textrm{mex} of an interval of a sequence as the smallest natural number that does not appear in the interval. Define the value of a sequence as the number of intervals whose mexk\textrm{mex}\geq k.

Given nn natural numbers less than mm and an interval [l,r][l,r], let f(k)f(k) denote, among all permutations of the sequence formed by these nn numbers, the maximum possible value of the sequence. For each k[l,r]k\in [l,r], find f(k)f(k).

Let aia_i denote the number of occurrences of number ii. It is guaranteed that there exists a positive integer XX such that im1,ai{X,X+1}\forall i\le m-1,a_i\in \{X,X+1\}.

Input Format

Since nn may be very large, the following method is used to reduce input size:

The first line contains four integers m,l,r,Xm,l,r,X.

The second line contains a binary string of length mm. If the ii-th position is 11, then the number of occurrences of i1i-1 is X+1X+1; otherwise, the number of occurrences is XX.

From the input, we can derive n=mX+Sn=mX+S, where SS is the number of 11's in the binary string.

Output Format

To reduce output size, let $ans=\displaystyle{\bigoplus_{i=l}^r} (233^if(i)\bmod 998244353)$, where \displaystyle\bigoplus denotes bitwise XOR in binary. Output one line containing the integer ansans.

2 0 1 2
10
3034
14 1 14 13
10110101110101
379883349

Hint

Explanation for Sample 1

In the sample sequence, there are 33 zeros and 22 ones. For any permutation, f(0)f(0) is always 1515. When the permutation is 01010\textrm{01010}, f(1)f(1) reaches its maximum value 1313. The answer is:

$$\displaystyle (233^0\times 15\bmod 998244353)\oplus(233^1\times 13\bmod 998244353)=3034$$

Constraints

  • Subtask 1 (5 points): n,m9n,m\leq 9.
  • Subtask 2 (15 points): n,m200n,m\leq 200.
  • Subtask 3 (15 points): n,m5×103n,m\leq 5\times 10^3.
  • Subtask 4 (5 points): m2m\leq 2l=0l=0r=1r=1
  • Subtask 5 (10 points): m106m\leq 10^6l=ml=mr=mr=m
  • Subtask 6 (10 points): m106m\leq 10^6X=1X=1si=0s_i=0
  • Subtask 7 (15 points): m106m\leq 10^6rl+1104r-l+1\leq 10^4
  • Subtask 8 (15 points): m2×106m\leq 2\times 10^6
  • Subtask 9 (10 points): No special constraints.

For all testdata, it holds that n109n\leq 10^9, m107m\leq 10^7, 0lrm0\leq l\leq r\leq m, X1X\geq 1.

Translated by ChatGPT 5