luogu#P5310. [Ynoi2011] 遥远的过去
[Ynoi2011] 遥远的过去
Background
When I was in the 6th grade, I learned Java and wrote a small game. It basically flung my math olympiad teacher’s head to hit frogs. Looks like I already understood mouha and P-head back then.
Now I feel I didn’t understand a lot at the time and was just writing randomly. The program was full of if’s, yet I still finished it and even won a first prize in a science and innovation contest (it could add 5 points to the high school entrance exam, definitely not shady!).
So I’ve always felt I actually like doing creative things. This will show up later too.
In middle school, because I had learned some elementary olympiad math and also some math contest stuff, I felt the classes were plain and wasn’t very interested.
I first encountered the informatics olympiad. It felt quite interesting, but I didn’t study it seriously.
Our school had OI training, but they taught Pascal. Since I had already learned Java, I naturally thought that language was outdated and trash, so I didn’t really listen. I remember I took a selection test and there was a “chicken and rabbit in the same cage” problem. I wrote a solution using equations and got points deducted. The teacher’s official solution was something like while( a-- ) b++. Then I decided not to go anymore.
In the 8th grade I took the NOIP Junior group and only got 120. The second problem was expression evaluation. I spent a long time on it and kept failing, then that was it.
After the exam I learned that several classmates were top 10 in the province. They seemed really strong. I was still very competitive back then, so I decided to study OI well and crush them in 9th grade.
In 9th grade I got 295 and got crushed by two 8th graders at the time, but I was the highest in 9th grade.
Those two kids seem to have gone to Cha Yuan now. Truly legends.
Middle school felt quite fun. Although I had to play mind games with a toxic teacher every day, it was still interesting.
[Remember to add images. Content: a screenshot of the small game, and the NOIP score.]
Since this is Ynoi, not a place for the problem setter to write strange essays, you now need to do a data structure problem:
Problem 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