| OCPC 2025 Summer, Day 8: Chromate Sent This to Dominater in His DMs and Dominater Said :---) Contest |
|---|
| Finished |
Let us define a function $$$f : \mathbb{Z}^m \to \mathbb{Z}^m$$$ on integer sequences as follows.
$$$$$$(f(a))_i = \sum_{i \lt j \le m}{\left[ \!\! \left[{\left ({\max_{i \lt k\le j}{a_k}}\right ) \lt a_i} \right ] \!\! \right]}$$$$$$
The expression $$$[\![ a \lt b ]\!]$$$ is $$$1$$$ if $$$a \lt b$$$ and $$$0$$$ otherwise. For example, $$$f([1,4,2,3,4,3])$$$ returns the sequence $$$[0,2,0,0,1,0]$$$.
You are given two integer sequences $$$a$$$ and $$$b$$$ of lengths $$$n$$$ and $$$m$$$ ($$$m \le n$$$).
Please find the number of indices $$$i$$$ such that $$$1 \le i \le n-m+1$$$ and $$$f([a_i,a_{i+1},\ldots,a_{i+m-1}])=f(b)$$$, and enumerate all such indices.
The first line contains two integers $$$n$$$ and $$$m$$$ — the lengths of $$$a$$$ and $$$b$$$ ($$$1 \le m \le n \le 300\,000$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line contains $$$m$$$ integers $$$b_1,b_2,\ldots,b_m$$$ ($$$1 \le b_i \le 10^9$$$).
Do note that the elements of $$$a$$$ and $$$b$$$ may contain duplicate elements.
On the first line, print the number $$$k$$$ of indices $$$i$$$ that satisfy $$$f([a_i,a_{i+1},\ldots,a_{i+m-1}])=f(b)$$$.
On the second line, output $$$k$$$ indices $$$i_1,i_2,\ldots,i_k$$$ that satisfy the condition in increasing order, separated by spaces ($$$1 \le i \le n-m+1$$$).
10 51 2 1 2 1 2 1 2 1 21 2 1 2 1
3 1 3 5
10 51 2 3 4 5 6 7 8 9 101 1 1 1 1
6 1 2 3 4 5 6
10 510 9 8 7 6 5 4 3 2 11 1 1 1 1
0
18 41 2 3 1 2 1 2 3 1 2 1 2 3 1 2 1 2 32 3 1 2
3 2 7 12
In the first example, $$$b=[1,2,1,2,1]$$$ and $$$f(b)=[0,1,0,1,0]$$$.
One can manually verify that $$$f([2,1,2,1,2])=[1,0,1,0,0]\neq[0,1,0,1,0]$$$.
In the second example, $$$b=[1,1,1,1,1]$$$ and $$$f(b)=[0,0,0,0,0]$$$.
| Name |
|---|


