Under construction

Still being built. Things may change

DP (Large)

Interview

Time limit4sMemory limit1024 MB

Summary
For each queried problem, find the longest subsequence of problems whose numbers and difficulties both strictly increase and that includes it.
Level

Medium5 of 10

Topics
Dynamic programming, Binary search
Solved
No attempts yet

Problem

This problem differs from DP (Small) in the limits on the number of problems, the number of queries, and the difficulty range.

DP is short for DYNAMIC Porani.

A DYNAMIC Porani likes to solve the problems she can solve in a DYNAMIC way. A DYNAMIC solution means solving as many problems as possible so that both the problem number and the difficulty strictly increase.

Over break, Porani received a set of recommended problems from her senior to improve her algorithm skills. Being lazy, she does not want to solve every problem. When a senior tells her to solve a certain problem, tell her how many problems she must solve in a DYNAMIC way that includes that problem.

Input

The first line contains two integers NN and QQ (1≤N≤300 0001 \le N \le 300\,000, 1≤Q≤N1 \le Q \le N), separated by a space.

The second line contains non-negative integers DiD_i (1≤i≤N1 \le i \le N; 0≤Di≤3×1080 \le D_i \le 3 \times 10^8), the difficulty of each problem in order of problem number, separated by spaces. Problem numbers are consecutive positive integers starting from 11.

From the third line, QQ lines follow, each containing a problem number AiA_i (1≤i≤Q1 \le i \le Q; 1≤Ai≤N1 \le A_i \le N) that a senior asked Porani to solve. The problem numbers in the queries are distinct.

Output

Print QQ lines. On line ii, print the number of problems Porani must solve for the ii-th senior instruction, in order.

Examples1

  1. Example 1

    Input
    6 6
    1 2 3 4 3 2
    1
    2
    3
    4
    5
    6
    
    Expected output
    4
    4
    4
    4
    3
    2