Tower 2
Time limit1sMemory limit128 MB
Each visitor climbs while taller than each step and stops below the previous visitor, and you report the highest step each one reaches.
- Level
Medium6 of 10
- Topics
- Segment tree, Simulation
- Solved
- No attempts yet
Problem
A tall tower has been built in a city. The stairway leading up the tower consists of steps, and each step has its own height. Step is at the very bottom of the tower, and steps with larger numbers are physically higher up.
visitors climb the tower one after another, in the given order. Each visitor has a height. To stand on a step, a visitor's height must be strictly greater than that step's height. As soon as a visitor reaches a step they cannot climb onto, they stop on the step just below it and can go no higher. The stairway is very narrow: once a visitor stops on some step, every visitor behind them is blocked and must stop at least one step lower than the visitor in front of them.
Given the height of each step and the height of each visitor, determine the number of the highest step each visitor ends up on, assuming they climb in the given order. If a visitor cannot climb onto even the first step, the answer for that visitor is .
Input
The first line contains two integers and (), the number of steps and the number of visitors.
The second line contains integers (), where is the height of the -th step from the bottom.
The third line contains integers (), where is the height of the -th visitor.
Output
Print integers on a single line, separated by spaces. Here is the number of the highest step the -th visitor can reach, or if they cannot climb onto any step.