This page is still under construction.

Parts of this page are still being built. What you see may change.

Tower 2

Time limit1sMemory limit128 MB

Summary
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 nn steps, and each step has its own height. Step 11 is at the very bottom of the tower, and steps with larger numbers are physically higher up.

mm 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 00.

Input

The first line contains two integers nn and mm (1≤n,m≤5000001 \le n, m \le 500000), the number of steps and the number of visitors.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i is the height of the ii-th step from the bottom.

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bi≤1091 \le b_i \le 10^9), where bib_i is the height of the ii-th visitor.

Output

Print mm integers w1,w2,…,wmw_1, w_2, \dots, w_m on a single line, separated by spaces. Here wiw_i is the number of the highest step the ii-th visitor can reach, or 00 if they cannot climb onto any step.

Examples3

  1. Example 1

    Input
    3 4
    2 5 1
    6 5 4 3
    
    Expected output
    3 1 0 0
    
  2. Example 2

    Input
    5 5
    1 1 1 1 1
    10 10 10 10 10
    
    Expected output
    5 4 3 2 1
    
  3. Example 3

    Input
    3 3
    5 5 5
    1 2 3
    
    Expected output
    0 0 0