#P10273. 大娱乐至上

大娱乐至上

Background

Glitter, black holes, the star that everyone watches.

In the most beautiful dream of the most beautiful land.

Her hair is more expensive than gold leaf, her lipprints can be worth bundles of cash.

But her heart, her heart, her heart,

Is not worth a single gold coin, not worth a single gold coin, not worth a glance.

Problem Description

You are given a string SS of length nn consisting of lowercase letters, and a binary string bb of length nn. bi=1b_i=1 means that SiS_i can be modified.

You are given mm substrings S[l,r]S_{[l,r]}. A substring strstr is defined to be non-partially-ordered if and only if it is possible to modify at most one position of SS so that, among the mm substrings, all substrings that were originally <str< str become str\ge str.

Formally, a pair (li,ri)(l_i,r_i) is non-partially-ordered if and only if there exists a string TT (obtained from SS by modifying at most one character) such that $\forall\,1 \le j \le m,[S_{[l_j,r_j]}<S_{[l_i,r_i]}]+[T_{[l_j,r_j]}<T_{[l_i,r_i]}]\not=2$.

Determine which substrings are non-partially-ordered.

Note that after modification, characters smaller than a or larger than z are allowed.

Input Format

The first line contains two integers n,mn,m.

The second line contains a string SS.

The third line contains a binary string bb.

The next mm lines each contain a pair (li,ri)(l_i,r_i).

Output Format

Output a binary string ansans of length mm. ansi=1ans_i=1 means that (li,ri)(l_i,r_i) is non-partially-ordered, and ansi=0ans_i=0 means it is not.

10 5
abbaababaa
0111111111
1 5
7 10
1 3
3 7
4 8
01111

Hint

Explanation of Sample 1

For convenience, assume the character smaller than a is #, and the character larger than z is *.

  • (1,5):(1,5): No matter how you modify, it always holds that S[1,3]<S[1,5],T[1,3]<T[1,5]S_{[1,3]}<S_{[1,5]},T_{[1,3]}<T_{[1,5]}.

  • (7,10):(7,10): TT can be abbcababaa.

  • (1,3):(1,3): TT can be a#baababaa.

  • (3,7):(3,7): TT can be ab#aababaa.

  • (4,8):(4,8): TT can be abbaababaa.

Constraints and Notes

This problem uses bundled testdata.

subtask1(10pt):\text{subtask1(10pt):} 1n,m1001 \le n,m \le 100.

subtask2(30pt):\text{subtask2(30pt):} 1n,m10001 \le n,m \le 1000.

subtask3(10pt):\text{subtask3(10pt):} bi=1b_i=1.

subtask4(50pt):\text{subtask4(50pt):} No special restrictions.

For all testdata, 1n,m2×105,1lirin1\le n,m \le 2\times 10^5,1 \le l_i \le r_i \le n. All inputs are integers and lowercase letters.

Translated by ChatGPT 5