#P7495. 异位坍缩

    ID: 4481 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>递推2021矩阵运算概率论,统计矩阵乘法

异位坍缩

Description

The god wants to test whether his believers are loyal, and he decides to use luck as the test.

The god has prepared nn questions in advance. Each question has two choices: “relatively radical” and “relatively conservative”. The god has already fixed his own choices.

To test his believers, the god will uniformly choose one from all feasible ways of selecting questions (a feasible way means choosing a consecutive kk questions, with lkrl\leq k\leq r, where l,rl,r are given). Then the believers will answer each of the kk questions in order with either “relatively radical” or “relatively conservative”. The god will judge whether a believer is loyal based on his own choices and that believer’s answers.

The judging rules are:

  • This is the first question: no matter what the answer is, the god is willing to believe the believer is loyal.
  • This is not the first question: if the believer’s previous answer is the same as the god’s choice, then the god will require them to explore more advanced choices, so the believer’s answer to this question cannot be more conservative than the god’s choice; otherwise, the god will require the believer to obey him, so the believer’s answer to this question cannot be more radical than the god’s choice.

If the believer’s answers satisfy the above requirements, then the believer is loyal.

Now, the god wants to know: if a believer answers each question uniformly at random with “relatively radical” or “relatively conservative”, what is the probability that the believer is loyal? He asks you this question through Fiona, and requires you to output the result modulo 998244353998244353. If you cannot answer in time, you will lose the god’s trust.


Simplified statement:

Given a binary string aa of length nn and l,r(lr)l,r(l\leq r).

For two binary strings p,qp,q of the same length kk, we say that qq is “loyal” to pp if and only if pp and qq satisfy:

  • For any 1<ik1<i\leq k, if qi1=pi1q_{i-1}=p_{i-1}, then qipiq_i\geq p_i, otherwise qipiq_i\leq p_i.

You need to compute the probability that: first, uniformly choose a substring of aa whose length kk satisfies lkrl\leq k\leq r, and then uniformly choose a binary string bb of length kk, such that bb is “loyal” to that substring. Output the result modulo 998244353998244353.

Input Format

The first line contains three integers n,l,rn,l,r, as described above.

The second line contains a string of length nn, representing aa. It is guaranteed that the string contains only characters 0 and 1.

Output Format

Output one integer in one line, representing the answer.

5 2 3
01101

338690049
17 4 13
10101110100101101

512357021

Hint

Explanation for Sample 1:

We use [l,r]\left[l,r\right] to denote the interval where the chosen substring lies.

  • Choose [1,2]\left[1,2\right]. The substring is 01, with length 22. There are 33 binary strings that are “loyal” to this substring, so the probability is 34\dfrac{3}{4}.

  • Choose [1,3]\left[1,3\right]. The substring is 011, with length 33. There are 44 binary strings that are “loyal” to this substring, so the probability is 12\dfrac{1}{2}.

  • Choose [2,3]\left[2,3\right]. The probability is 34\dfrac{3}{4}.

  • Choose [2,4]\left[2,4\right]. The probability is 58\dfrac{5}{8}.

  • Choose [3,4]\left[3,4\right]. The probability is 34\dfrac{3}{4}.

  • Choose [3,5]\left[3,5\right]. The probability is 12\dfrac{1}{2}.

  • Choose [4,5]\left[4,5\right]. The probability is 34\dfrac{3}{4}.

So the result is $\dfrac{\dfrac{3}{4}+\dfrac{1}{2}+\dfrac{3}{4}+\dfrac{5}{8}+\dfrac{3}{4}+\dfrac{1}{2}+\dfrac{3}{4}}{7}=\dfrac{37}{56}$, which is 338690049338690049 modulo 998244353998244353.


This problem uses bundled testdata.

  • Subtask 1 ( 1%1\% ): n=1n=1.
  • Subtask 2 ( 13%13\% ): n100n\leq100.
  • Subtask 3 ( 3%3\% ): Guaranteed that 1in,ai=0\forall1\leq i\leq n,a_i=0.
  • Subtask 4 ( 3%3\% ): Guaranteed that 1in,ai=1\forall1\leq i\leq n,a_i=1.
  • Subtask 5 ( 20%20\% ): n103n\leq10^3.
  • Subtask 6 ( 15%15\% ): l=rl=r.
  • Subtask 7 ( 20%20\% ): n5×105n\leq 5\times 10^5.
  • Subtask 8 ( 25%25\% ): No special constraints.

Constraints: for all testdata, 1n5×106,1lrn1\leq n\leq5\times 10^6,1\leq l\leq r\leq n

Translated by ChatGPT 5