QOJ.ac

QOJ

حد الوقت: 3.5 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#8630. Character Tree

الإحصائيات

Given a tree where each edge has a character assigned to it. A constant $X$ is given.

There are two types of operations, each consisting of three integers and a string:

1 x y S: For the directed simple path from $x$ to $y$, replace the character on the $i$-th edge of the path with the corresponding character $S_i$ from string $S$. It is guaranteed that the number of edges on the path from $x$ to $y$ is $X$.

2 x y S: Query the number of occurrences of $S$ in the string formed by the directed simple path from $x$ to $y$. (Matching here means: treating $S$ as a pattern string and matching it position by position along the string formed by the path.) For example, if $S=121$ and the string on the path is $1212122$, there are 2 matches, occurring at positions $[1,3]$ and $[3,5]$.

The indices of all strings $S$ mentioned above are 1-based, and it is guaranteed that the length of every input string $S$ is $X$.

Input

The first line contains three space-separated integers $n, m, X$.

The next line contains $n-1$ integers, where the $i$-th number represents the parent $f_{i+1}$ of node $i+1$. It is guaranteed that the parent's index is smaller than the node's index.

The next line contains $n-1$ characters, where the $i$-th character represents the character $a_{i+1}$ on the edge between node $i+1$ and its parent.

The next $m$ lines each contain three space-separated integers $opt, x, y$ and a string $S$ of length $X$, representing an operation.

Output

For each type 2 operation, output the answer on a new line.

Examples

Input 1

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

Output 1

1
1
1
0

Subtasks

For $10\%$ of the data, $1\le n, m\le 250$.

For another $10\%$ of the data, there are no type 1 operations.

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

For another $10\%$ of the data, $X\le 3$.

For another $10\%$ of the data, $X\ge 20000$.

For another $10\%$ of the data, $f_i=i-1$.

For another $10\%$ of the data, $a_i\le 1$.

For another $10\%$ of the data, $1\le n, m\le 2.5\times 10^4$ and $mX\le 2.5\times 10^4$.

For another $10\%$ of the data, $1\le n, m\le 2.5\times 10^5$ and $mX\le 2.5\times 10^5$.

For $100\%$ of the data, $1\le n, m, X\le 5\times 10^5$, the character set consists of integers in $[1,9]$, and $mX\le 5\times 10^5$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.