#P9997. [Ynoi2000] pmpkmp

[Ynoi2000] pmpkmp

Problem Description

Given a tree, each edge of the tree has a character on it. A constant XX is given.

There are two types of operations. Each operation inputs three integers and a string:

1 x y S: For the edges on the directed simple path from xx to yy, replace the character on the ii-th edge of the path with the corresponding character SiS_i in SS. It is guaranteed that the number of edges on the path from xx to yy is XX.

2 x y S: Query the number of matches of SS on the string formed by the directed simple path from xx to yy (here, matching means: treat SS as the pattern string and match it against the path string position by position). For example, if S=121S = 121 and the path string is 12121221212122, then it matches 2 times, at positions [1,3][1,3] and [3,5][3,5].

For all strings SS above, indices start from 11. It is guaranteed that the length of every input string is XX.

Input Format

The first line contains three integers n,m,Xn, m, X separated by spaces.

The next line contains n1n - 1 integers. The ii-th integer denotes the parent fi+1f_{i+1} of node i+1i+1. It is guaranteed that the parent index of each node is smaller than the node index.

The next line contains n1n - 1 characters. The ii-th character denotes the character ai+1a_{i+1} on the edge from node i+1i+1 to its parent.

Then follow mm lines. Each line contains three integers opt,x,yopt, x, y separated by spaces and a string SS of length XX, representing one operation.

Output Format

Output a total of mm lines. Each line contains one integer, representing the answer to each operation of type 22.

10 7 2
1 2 3 2 3 3 3 3 7
212111121
2 1 4 21
1 10 3 21
1 9 7 22
2 2 10 12
2 6 8 11
1 9 8 12
2 4 7 11
1
1
1
0

Hint

Idea: nzhtl1477, Solution: ComeIntoPower&nzhtl1477&ccz181078, Code: ccz181078, Data: ccz181078.

Constraints:

For 10%10\% of the testdata, 1n,m2501 \le n, m \le 250.

For another 10%10\% of the testdata, there are no type 11 operations.

For another 10%10\% of the testdata, X=1X = 1.

For another 10%10\% of the testdata, X3X \le 3.

For another 10%10\% of the testdata, X20000X \ge 20000.

For another 10%10\% of the testdata, fi=i1f_i = i - 1.

For another 10%10\% of the testdata, ai1a_i \le 1.

For another 10%10\% of the testdata, 1n,m2.5×1041 \le n, m \le 2.5 \times 10^4, and mX2.5×104mX \le 2.5 \times 10^4.

For another 10%10\% of the testdata, 1n,m2.5×1051 \le n, m \le 2.5 \times 10^5, and mX2.5×105mX \le 2.5 \times 10^5.

For 100%100\% of the testdata, 1n,m,X5×1051 \le n, m, X \le 5 \times 10^5. The alphabet consists of integers in [1,9][1,9], and mX5×105mX \le 5 \times 10^5.

Translated by ChatGPT 5