luogu#P4696. [CEOI 2011] Matching
[CEOI 2011] Matching
Problem Description
For an integer sequence and a permutation of , we say that matches if and only if:
- Any two numbers in are different from each other.
- After sorting in increasing order, we obtain .
Now you are given a permutation of and a sequence . Please determine which substrings of match the permutation .
Input Format
The first line contains two positive integers separated by spaces.
The second line contains positive integers separated by spaces, representing the permutation .
The third line contains positive integers separated by spaces, representing the sequence .
Output Format
The first line contains an integer , indicating the number of substrings that match .
The second line contains positive integers separated by spaces, indicating the starting positions of these substrings (indexed from ). Output these positions in increasing order. In particular, if , you should output an empty line as well.
5 10
2 1 5 3 4
5 6 3 8 12 7 1 10 11 9
2
2 6
Hint
For of the testdata, $2\le n\le m\le 1\ 000\ 000;1\le h_i\le 10^9;1\le p_i\le n$. It is guaranteed that all elements in are pairwise distinct, and is a permutation.
Constraints
Translated by ChatGPT 5