#P6640. [BJOI2020] 封印

[BJOI2020] 封印

Description

Given two strings s,ts, t that contain only lowercase letters a,ba, b, there are qq queries. In each query, ask for the length of the longest common substring of s[lr]s[l \dots r] and tt.

Input Format

The input has q+3q+3 lines.

The first line contains a string ss.

The second line contains a string tt.

The third line contains an integer qq.

The next qq lines each contain two integers li,ri(1liris)l_i, r_i(1\le l_i \le r_i \le |s|), representing one query.

Output Format

Output has qq lines.

The ii-th line is the length of the longest common substring of s[liri]s[l_i \dots r_i] and tt.

aaba
aaaabbbaa
3
1 4
1 3
2 4
3
3
2

Hint

Test Point ID s,t\vert s\vert , \vert t\vert \le qq\le
11 5050
2,32,3 2×1032\times 10^3
4,54,5 2×1052\times 10^5 1010
6106\sim 10 2×1052\times 10^5

Translated by ChatGPT 5