#P14744. [ICPC 2021 Seoul R] Stock Price Prediction
[ICPC 2021 Seoul R] Stock Price Prediction
题目描述
Mr. Kim is a stock market analyst. Recently, he found something interesting while looking at the stock charts of several companies. Most of the stocks that rose for four consecutive days fell the next day. Also, the stock price that fell on the fifth day was often located between the price of the second and third days of the stock price during the four days of the uptrend. For example, Company A's stock price was won, won, won, and won for four consecutive days, and the fifth day's stock price of Company A was won. Also, Company B's stock price was won, won, won, and won for four consecutive days, and the fifth day's stock price of Company B was won.
Mr. Kim thinks that if he can find a part in the previous stock price sequence that matches the price movement pattern over the last few days, he will be able to predict the stock price for the next day quite accurately. He also thinks that the relative ranks in a stock price sequence are more important than the actual prices because if the relative ranks of two stock price sequences are the same, their patterns in charts look similar. In the above example, the stock price sequence of Company A for five consecutive days, won, won, won, won, won, can be represented as because is the smallest among the five numbers, is the second smallest, is the fourth, and so on. Moreover, the stock price of Company B for five consecutive days, won, won, won, won, won, can also be represented as due to the same reason. Their relative ranks are the same and their charts of five consecutive days look very similar as shown in Figure K.1.
:::align{center}

Figure K.1 Charts of Company A and B for five consecutive days :::
Mr. Kim decided to consider two sequences as a match if all the relative ranks of same positions of two sequences are the same. Mr. Kim formally defined R-match of two sequences of same length (number of integers) as follows: Two sequences of integers and of the same length are an R-match if and only if for each (), 's rank in and 's rank in are the same. Next, he defined the R-pattern matching problem as follows: Given two sequences of integers of length and of length (), find every position of such that and are an R-match. For example, when , and , and are an R-match. Also, and are an R-match.
Given two sequences of integers of length and of length (), write a program to solve the R-pattern matching problem for and .
输入格式
Your program is to read from standard input. The input starts with a line containing two integers, and (, , ), where is the length of , and is the length of . In the second line, the integers in are given in turn. In the third line, the integers in are given in turn. Each integer in and ranges from to .
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain every position of such that and are an R-match. Each position must appear in increasing order. If there is no such position, print .
5 12
500 560 600 680 580
30 25 40 60 70 90 65 30 35 50 55 40
3 8
5 15
1000 1200 1400 1700 1350
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
0
6 14
33 40 22 40 41 28
10 20 16 27 32 12 32 33 20 25 15 25 31 17
4 9