#P8947. Angels & Demons

    ID: 9967 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>线段树2023洛谷原创后缀自动机 SAMO2优化

Angels & Demons

Background

The Pope’s chamberlain had already felt pain in his body. The pain quickly spread through his whole body, making him want to grab and scratch.

Do not forget the suffering Jesus endured.

He felt a burning pain in his throat, and even morphine could not relieve it.

What I had to do here is already done.

He had stirred awe in people’s hearts, and people had hope again.

When he was in the Pallium niche, the Pope’s chamberlain followed God’s teaching and performed the anointing ritual. His body, his hair and beard, his cheeks, his linen robe—everything was covered with lamp oil. At this moment, it was as if he were soaked in sacred green lamp oil, smelling sweet like a mother’s natural scent, yet highly flammable. He would be fortunate to ascend to Heaven. It would be a miraculous and swift process. What he would leave to the world would no longer be scandal... but a new power and a miracle.

His hand slipped into the pocket of his robe and took out the small golden lighter he had brought from the Pallium niche.

He softly spoke a sentence that God had said at the Last Judgment.

Blazing flames rush into the sky, and God’s angels will also ascend in the fire.

His thumb pressed down on the lighter.

People were still singing hymns in St. Peter’s Square...

Problem Description

Given nn template strings S1...nS_{1...n} consisting of lowercase letters, and qq queries. The queries are of the following two types:

  1. 1 T: Given a query string TT consisting of lowercase letters.
  2. 2 p l r: Let num(p,l,r)num(p,l,r) denote how many query strings have the substring Sp[l,r]S_p[l,r] as a substring. Compute maxi=1l(num(p,i,r))\max\limits_{i=1}^{l}(num(p,i,r)).

Input Format

The first line contains three integers n,q,w0n, q, w_0, where w0w_0 indicates the data type.

  • w0=0w_0 = 0:

    Lines 22 to n+1n + 1 each contain one string. Line i+1i + 1 gives SiS_i.

    The next qq lines each contain one query, in the format described above.

  • w0=1w_0 = 1:

    The second line contains three integers A,B,CA, B, C.

    The next nn lines each contain one string, representing a template string.

    Then, the queries are generated by the following code (in the code, lst denotes the answer of the previous type 22 query, initially 00; le[i] denotes the length of template string ii; and s is a char array):

while (q--) {
	int op;
	scanf("%d", &op);
	if (op == 1) {
		scanf("%s", s + 1);
		int x((1ll * A * lst + B) % C), l(strlen(s + 1));
		for (int i(1); i <= l; ++i) {
			swap(s[i], s[x % l + 1]);
			x = (1ll * A * x + B) % C;
		}
	} else {
		int p, l, r;
		scanf("%d%d%d", &p, &l, &r);
		int x((1ll * A * lst + B) % C);
		p = (p + x) % n + 1;
		x = (1ll * A * x + B) % C;
		l = (l + x) % le[p] + 1;
		x = (1ll * A * x + B) % C;
		r = (r + x) % le[p] + 1;
		if (l > r) swap(l, r);
		// update lst here
	}
}

Output Format

For each type 22 query, output one line containing one integer, the answer.

5 11 0
abb
aab
baab
bbaa
aabbb
1 ab
2 1 1 3
2 2 2 3
1 ba
2 3 1 2
2 4 1 2
2 4 2 3
1 abb
2 5 2 4
2 1 1 3
2 1 1 2

0
1
1
0
1
1
1
2

5 11 1
114 514 1919810
abb
aab
baab
bbaa
aabbb
1 ab
2 1 1 3
2 2 2 3
1 ba
2 3 1 2
2 4 1 2
2 4 2 3
1 abb
2 5 2 4
2 1 1 3
2 1 1 2

0
0
1
0
0
1
1
0

Hint

Constraints for 100%100\% of the testdata: 1n,q1051 \le n, q \le 10^5, i=1nSi5×105\sum\limits_{i=1}^{n}|S_i| \le 5 \times 10^5, T5×105\sum|T| \le 5 \times 10^5, 1pn1 \le p \le n, w0{0,1}w_0 \in \{0,1\}, 1A,B<C1091 \le A, B < C \le 10^9.

Test Point Score nn \le i=1nSi\sum\limits_{i=1}^{n}|S_i|\le qq \leq T\sum |T| \leq w0=w_0= Other Limits
11 33 2020 200200 200200 50005000 00 None.
22 200200 20002000
33
44 5×1055\times10^5
55
66 11 5×1055\times10^5 22
77
88 44 10510^5 10510^5 10510^5 10510^5
99 33 Strings are random.
1010 44 2×1052 \times 10^5 2×1052 \times 10^5 None.
1111 33 Strings are random.
1212 44 3×1053 \times 10^5 3×1053 \times 10^5 None.
1313 33 Strings are random.
1414 44 4×1054 \times 10^5 4×1054 \times 10^5 None.
1515 33 Strings are random.
1616 44 5×1055\times10^5 5×1055\times10^5 None.
1717 33 Strings are random.
1818 2×1052 \times 10^5 None.
1919 3×1053 \times 10^5
2020 4×1054 \times 10^5
2121 5×1055\times10^5 Strings are random.
2222 None.
2323
2424
2525
2626 44 3×1053\times10^5 11
2727 4×1054\times10^5
2828 5×1055\times10^5
2929
3030

Test points 88 to 1717 guarantee that for all type 22 queries, l=1l = 1.

Translated by ChatGPT 5