#P7409. SvT

    ID: 8279 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串图论后缀自动机 SAM虚树后缀数组 SA后缀树

SvT

Background

(I do not want to tell you what the problem name is supposed to mean.)

Problem Description

You are given a string SS of length nn that contains only lowercase letters, with indices in [1,n][1,n].

Now there are multiple queries. For each query, we are given several suffixes (represented by their starting positions in SS). Find the sum of the LCP (Longest Common Prefix) lengths over all unordered pairs among these suffixes. The LCP length of a pair of suffixes is counted only once.

Input Format

The first line contains two positive integers n,mn,m, representing the length of SS and the number of queries.

The next line contains a string SS.

Then follow mm queries. For each query, the following format is given on one line:

First an integer tt, meaning there are tt suffixes. Then tt integers follow, each indicating the starting position of one suffix in the string SS.

Output Format

For each query, output one integer per line, representing the answer to that query. Since the answer may be very large, you only need to output the remainder of the answer modulo 23333333333333333\text{23333333333333333} (a huge prime).

7 3
popoqqq
1 4
2 3 5
4 1 2 5 6
0
0
2

Hint

Sample explanation:

For query 1, there is only one suffix oqqq, so the answer is 00.

For query 2, there are two suffixes poqqq and qqq. Their LCP is 00, so the answer is 00.

For query 3, there are four suffixes popoqqq, opoqqq, qqq, qq. Only the pair qqq and qq has a non-zero LCP, with length 22, so the answer is 22.

Constraints:

For 100%100\% of the testdata, S5×105|S|\le 5\times 10^5, and t3×106\sum t\le 3\times10^6.

Special note: Due to changes in some parameters in another world line, for a query, even if a suffix appears multiple times, it is counted only once.

Source: bzoj 3879.

Translated by ChatGPT 5