luogu#P8571. [JRKSJ R6] Dedicatus545

    ID: 7274 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2022洛谷原创后缀自动机 SAMO2优化分治虚树分块AC 自动机

[JRKSJ R6] Dedicatus545

Background

Problem Description

For strings x,yx, y, define w(x,y)w(x, y) as the number of occurrences of xx in yy.

Index gives you nn strings s1ns_{1\dots n} and mm queries. Each query provides l,r,kl, r, k. You need to compute maxi=lrw(si,sk)\max_{i=l}^r w(s_i, s_k).

Input Format

The first line contains two integers n,mn, m.
The next nn lines each contain a string consisting only of lowercase letters, representing s1ns_{1\dots n}.
The next mm lines each contain three integers l,r,kl, r, k, representing a query.

Output Format

For each query, output one integer per line representing the answer.

6 3
dedicatus
a
misaka
mikoto
mi
aaa
1 5 6
1 2 4
1 5 4
3
0
1

Hint

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} n,qn, q\le s\sum\vert s\vert\le Score\text{Score} Special property
11 2×1032\times10^3 10410^4 2020 None
22 5×1045\times10^4 3×1053\times 10^5
33 10510^5 5×1055\times10^5 All strings are pairwise distinct
44 4040 None

For 100%100\% of the data, 1n,m1051\le n, m\le 10^5, 1s5×1051\le \sum |s|\le 5\times 10^5, 1lrn1\le l\le r\le n, 1kn1\le k\le n.

Data: abruce&critnos&fjy666

Translated by ChatGPT 5