This page is still under construction.

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

Pilot

Time limit1sMemory limit512 MB

Summary
For each of Q altitude limits, count subarrays of heights whose maximum is at most that limit.
Level

Medium7 of 10

Topics
Stack, Sorting, Prefix sum, Array
Solved
No attempts yet

Problem

Rar the Cat has finally fulfilled his childhood dream of becoming a pilot, and wants to take his friend Dinosaur on a few scenic flights. Rar lives on a linear world, which can be described as a series of N integers, where the ith integer HiH_i is the height of the ith mountain from the leftmost edge of his world.

For example, the world described by N=6N = 6, H={1,3,2,4,1,2}H = \{1, 3, 2, 4, 1, 2\} looks like this:

Rar has a total of Q planes that he wants to show off, where the ith plane has a maximum cruising altitude of YiY_i metres. Each flight starts at the sth mountain and ends at the eth mountain. We may assume that s≤es \le e, i.e. Rar always flies toward the right. Since each of his planes has a maximum cruising altitude, he cannot fly across, take off from, or land on a mountain whose height is greater than its cruising altitude, i.e. Rar can fly over the ith mountain with the jth plane only if Hi≤YjH_i \le Y_j.

For the ith plane, help Rar determine the total number of different flights he can take, i.e. the total number of pairs (s, e) such that s≤es \le e and no mountain between s and e inclusive has height greater than YiY_i.

Input

Your program must read from standard input.

The first line of input contains two integers, N and Q.

The second line of input contains N integers, H1,…,HNH_1, \dots, H_N.

The third line of input contains Q integers, Y1,…,YQY_1, \dots, Y_Q.

Output

Your program must print to standard output.

The output contains Q lines with one integer each, where the number on the ith line is the total number of different flights Rar can take with his ith plane.

Constraints

  • 1≤N,Q,Hi,Yi≤1061 \le N, Q, H_i, Y_i \le 10^6

Examples3

  1. Example 1

    Input
    6 3
    1 3 2 4 1 2
    2 3 4
    
    Expected output
    5
    9
    21
    
  2. Example 2

    Input
    6 3
    2 2 5 2 2 2
    1 2 10
    
    Expected output
    0
    9
    21
    
  3. Example 3

    Input
    2 1
    1 2
    1000000
    
    Expected output
    3