#P5310. [Ynoi2011] 遥远的过去
[Ynoi2011] 遥远的过去
Description
Little F decides to design a language with a huge character set — the Z language — even if extra characters are sometimes useless.
Features of this language:
- The character set is extremely large, possibly with distinct characters.
- Each word is made of a sequence of pairwise distinct characters.
- Characters can be compared for equality and order, so we will use numbers to represent the strange characters in the Z language.
- Two words that look completely different can still be the same word because: as long as the positions of the -th largest characters are the same in both words for every , then they are essentially the same word. For example, and are the same. (So you can conveniently use the Z language to encrypt information!)
Now, Little F plans to apply the Z language to a real task. For example, he opens an algorithm problem on a computer:
Given two strings and , find how many times is matched as a substring in .
Little F knows this is a basic problem solvable with KMP. However, when implementing Z-KMP for matching in the Z language, he ran into trouble. Can you help him?
To verify you really understand what Little F means, he will modify string many times and ask you. No slacking!
See the input and output formats for the operations your program must support.
Input Format
The first line contains two integers (), the lengths of strings and , and the number of operations.
The second line contains non-negative integers. The -th is the -th character of string ().
The third line contains non-negative integers. The -th is the -th character of string ().
Then follow lines. Each line contains two positive integers (), meaning the character at position in is changed from to .
The testdata guarantees that at any time, both and are valid Z strings that satisfy the above requirements.
Output Format
After each modification, output the number of times is Z-matched as a substring in .
5 3 2
11 7 5 3 2
3 2 1
2 5
1 6
0
3
Hint
Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477 (partially uploaded).
Sample 1 Explanation:
- After the first modification, cannot be matched by any substring of .
- After the second modification, can be matched by every length- substring of , because is strictly decreasing and is also strictly decreasing, so positions of characters with the same ranks coincide.
Subtasks:
- Subtask (31 pts): , .
- Subtask (41 pts): , .
- Subtask (78 pts): .
Translated by ChatGPT 5
京公网安备 11011102002149号