CF547E.Mike and Friends

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

What-The-Fatherland is a strange country! All phone numbers there are strings consisting of lowercase English letters. What is double strange that a phone number can be associated with several bears!

In that country there is a rock band called CF consisting of nn bears (including Mike) numbered from 11 to nn .

Phone number of ii -th member of CF is sis_{i} . May 17th is a holiday named Phone Calls day. In the last Phone Calls day, everyone called all the numbers that are substrings of his/her number (one may call some number several times). In particular, everyone called himself (that was really strange country).

Denote as call(i,j)call(i,j) the number of times that ii -th member of CF called the jj -th member of CF.

The geek Mike has qq questions that he wants to ask you. In each question he gives you numbers l,rl,r and kk and you should tell him the number

输入格式

The first line of input contains integers nn and qq ( 1<=n<=2×1051<=n<=2×10^{5} and 1<=q<=5×1051<=q<=5×10^{5} ).

The next nn lines contain the phone numbers, ii -th line contains a string sis_{i} consisting of lowercase English letters ().

The next qq lines contain the information about the questions, each of them contains integers l,rl,r and kk ( 1<=l<=r<=n1<=l<=r<=n and 1<=k<=n1<=k<=n ).

输出格式

Print the answer for each question in a separate line.

输入输出样例

  • 输入#1

    5 5
    a
    ab
    abab
    ababab
    b
    1 5 1
    3 5 1
    1 5 2
    1 5 3
    1 4 5
    

    输出#1

    7
    5
    6
    3
    6
    
首页