CF741E.Arpa’s abnormal DNA and Mehrdad’s deep interest

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D

Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.

Sipa put Arpa under the DNA editor. DNA editor showed Arpa's DNA as a string SS consisting of nn lowercase English letters. Also Sipa has another DNA TT consisting of lowercase English letters that belongs to a normal man.

Now there are (n+1)(n+1) options to change Arpa's DNA, numbered from 00 to nn . ii -th of them is to put TT between ii -th and (i+1)(i+1) -th characters of SS ( 0<=i<=n0<=i<=n ). If i=0i=0 , TT will be put before SS , and if i=ni=n , it will be put after SS .

Mehrdad wants to choose the most interesting option for Arpa's DNA among these n+1n+1 options. DNA AA is more interesting than BB if AA is lexicographically smaller than BB . Mehrdad asked Sipa qq questions:

Given integers l,r,k,x,yl,r,k,x,y , what is the most interesting option if we only consider such options ii that l<=i<=rl<=i<=r and ? If there are several most interesting options, Mehrdad wants to know one with the smallest number ii .

Since Sipa is a biology scientist but not a programmer, you should help him.

输入格式

The first line contains strings SS , TT and integer qq ( 1<=S,T,q<=1051<=|S|,|T|,q<=10^{5} ) — Arpa's DNA, the DNA of a normal man, and the number of Mehrdad's questions. The strings SS and TT consist only of small English letters.

Next qq lines describe the Mehrdad's questions. Each of these lines contain five integers l,r,k,x,yl,r,k,x,y ( 0<=l<=r<=n0<=l<=r<=n , 1<=k<=n1<=k<=n , 0<=x<=y<k ).

输出格式

Print qq integers. The jj -th of them should be the number ii of the most interesting option among those that satisfy the conditions of the jj -th question. If there is no option ii satisfying the conditions in some question, print -1.

输入输出样例

  • 输入#1

    abc d 4
    0 3 2 0 0
    0 3 1 0 0
    1 2 1 0 0
    0 1 3 2 2
    

    输出#1

    2 3 2 -1 
    
  • 输入#2

    abbbbbbaaa baababaaab 10
    1 2 1 0 0
    2 7 8 4 7
    2 3 9 2 8
    3 4 6 1 1
    0 8 5 2 4
    2 8 10 4 7
    7 10 1 0 0
    1 4 6 0 2
    0 9 8 0 6
    4 8 5 0 1
    

    输出#2

    1 4 2 -1 2 4 10 1 1 5 
    

说明/提示

Explanation of first sample case:

In the first question Sipa has two options: dabc ( i=0i=0 ) and abdc ( i=2i=2 ). The latter (abcd) is better than abdc, so answer is 22 .

In the last question there is no ii such that 0<=i<=10<=i<=1 and .

首页