#P13242. 「2.48sOI R1」你的名字

    ID: 14403 远端评测题 5000ms 1536MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>可持久化线段树分块后缀数组 SA

「2.48sOI R1」你的名字

Background

Problem Description

Since you cannot swap bodies, you need to solve a problem.

Let occ(u,v)\operatorname{occ}(u,v) be the number of occurrences of string v\boldsymbol v in string u\boldsymbol u. Let t[l,r]t[l,r] denote the substring of string tt consisting of the ll-th to the rr-th characters.

Given a sequence of strings (s1,,sn)(s_1,\dots,s_n), a sequence of positive integers (a1,,an)(a_1,\dots,a_n), and a string tt, there are qq queries. Each query has four parameters l1,r1,l2,r2l_1,r_1,l_2,r_2. Compute:

$$\sum\limits_{i=l_1}^{r_1}\left(\operatorname{occ}(s_i,t[l_2,r_2])\times\min\limits_{j=l_1}^{i}a_j\right)$$

For the subtask with o=1o=1, you need to support online queries.

Input Format

There are n+q+3n+q+3 lines in total.

  • The first line contains six positive integers sid,n,q,o,L,R\text{sid},n,q,o,L,R. Here sid\text{sid} indicates the Subtask ID of the test point. In particular, for the sample, sid=0\text{sid}=0. The meanings of the other values are as described in the statement.

  • Lines 22 to n+1n+1: nn strings (s1,,sn)(s_1,\dots,s_n).

  • Line n+2n+2: a string tt.

  • Line n+3n+3: nn positive integers (a1,,an)(a_1,\dots,a_n).

  • Lines n+4n+4 to n+q+3n+q+3: each line contains four positive integers L1,R1,L2,R2L_1,R_1,L_2,R_2, describing a query.

For the ii-th query, let the answer to the (i1)(i-1)-th query be lst\text{lst} (if i=1i=1, then lst=0\text{lst}=0). Then l1,l2,r1,r2l_1,l_2,r_1,r_2 are computed as:

  • l1=(L1+o×lst1)modn+1l_1=(L_1+o\times\text{lst}-1)\bmod n+1.
  • r1=(R1+o×lst1)modn+1r_1=(R_1+o\times\text{lst}-1)\bmod n+1.
  • l2=(L2+o×lst1)modt+1l_2=(L_2+o\times\text{lst}-1)\bmod |t|+1.
  • r2=(R2+o×lst1)modt+1r_2=(R_2+o\times\text{lst}-1)\bmod |t|+1.

If l1>r1l_1>r_1, swap l1,r1l_1,r_1. Do the same for l2,r2l_2,r_2.

When L1L\ne -1, you need to change all l1l_1 to LL; when R1R\ne -1, you need to change all r1r_1 to RR (if the initial l1>r1l_1>r_1, this operation is performed after swapping l1,r1l_1,r_1).

Output Format

There are qq lines. The ii-th line gives the result of the ii-th query in the formal statement.

0 6 6 0 -1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
614
492
895
820
247
0 6 6 1 -1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
900
287
1344
820
41

0 6 6 1 1 -1
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
1662
1358
824
1184
165

0 6 6 1 -1 6
aaaaabababaabab
baaabaabababaabba
aabababbaabaabab
abaababababaabaaaba
baabababababaaababa
bababaababababaabab
baababababaaaaababbbaaababaabababaabb
114 51 41 91 98 10
1 6 16 18
2 5 11 12
3 4 1 2
1 5 4 6
3 5 3 4
1 5 7 12
955
900
430
348
41
0

Hint

Sample Explanation #1

Take the last query as an example: t[7,12]=ababaat[7,12] = \texttt{ababaa}. The needed occ\text{occ} values are:

  • $\text{occ}(s_1,t[7,12])=\text{occ}(s_2,t[7,12])=\text{occ}(s_4,t[7,12])=\text{occ}(s_5,t[7,12])=1$.
  • occ(s3,t[7,12])=0\text{occ}(s_3,t[7,12])=0.

So the answer is $114\times 1+51\times 1+41\times 0 + 41\times 1 + 41\times 1 = 247$.

Constraints

This problem uses bundled testdata.

Let m=i=1nsim=\sum\limits_{i=1}^n\lvert s_i\rvert.

sid=\text{sid}= n,m,tn,m,\lvert t\rvert\le qq\le aia_i\le o=o= Special Properties Score Subtask Dependencies
11 100100 10910^9 00 55
22 2×1052\times 10^5 11 A\text{A} 1010
33 11 1515
44 10410^4 10910^9 00 11
55 2×1052\times 10^5 2020 44
66 11 B\text{B} 55
77 C\text{C} 2020
88 1010 2,3,5,6,72,3,5,6,7

Special Property A\text{A}: both sis_i and tt are a.

Special Property B\text{B}: L=1L=1.

Special Property C\text{C}: R=nR=n.

For 100%100\% of the data: 1n,m,t2×1051\le n,m,\lvert t\rvert\le 2\times 10^5, 1q2×1051\le q\le 2\times 10^5, 1ai1091\le a_i\le 10^9, o{0,1}o\in\{0,1\}, 0sid80\le \text{sid}\le 8, and 1L,Rn1\le L,R\le n or L,R=1L,R=-1.

Translated by ChatGPT 5