CF666E.Forensic Examination

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The country of Reberland is the archenemy of Berland. Recently the authorities of Berland arrested a Reberlandian spy who tried to bring the leaflets intended for agitational propaganda to Berland illegally . The most leaflets contain substrings of the Absolutely Inadmissible Swearword and maybe even the whole word.

Berland legal system uses the difficult algorithm in order to determine the guilt of the spy. The main part of this algorithm is the following procedure.

All the mm leaflets that are brought by the spy are numbered from 11 to mm . After that it's needed to get the answer to qq queries of the following kind: "In which leaflet in the segment of numbers [l,r][l,r] the substring of the Absolutely Inadmissible Swearword [pl,pr][p_{l},p_{r}] occurs more often?".

The expert wants you to automate that procedure because this time texts of leaflets are too long. Help him!

输入格式

The first line contains the string ss ( 1<=s<=51051<=|s|<=5·10^{5} ) — the Absolutely Inadmissible Swearword. The string ss consists of only lowercase English letters.

The second line contains the only integer mm ( 1<=m<=51041<=m<=5·10^{4} ) — the number of texts of leaflets for expertise.

Each of the next mm lines contains the only string tit_{i} — the text of the ii -th leaflet. The sum of lengths of all leaflet texts doesn't exceed 51045·10^{4} . The text of the leaflets consists of only lowercase English letters.

The next line contains integer qq ( 1<=q<=51051<=q<=5·10^{5} ) — the number of queries for expertise.

Finally, each of the last qq lines contains four integers ll , rr , plp_{l} , prp_{r} ( 1<=l<=r<=m,1<=pl<=pr<=s1<=l<=r<=m,1<=p_{l}<=p_{r}<=|s| ), where s|s| is the length of the Absolutely Inadmissible Swearword.

输出格式

Print qq lines. The ii -th of them should contain two integers — the number of the text with the most occurences and the number of occurences of the substring [pl,pr][p_{l},p_{r}] of the string ss . If there are several text numbers print the smallest one.

输入输出样例

  • 输入#1

    suffixtree
    3
    suffixtreesareawesome
    cartesiantreeisworsethansegmenttree
    nyeeheeheee
    2
    1 2 1 10
    1 3 9 10
    

    输出#1

    1 1
    3 4
    
首页