Interval Tree
题号:NC15416
时间限制:C/C++/Rust/Pascal 5秒,其他语言10秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Interval tree can be regarded as an extension of traditional segment tree: each vertex in interval tree still represents a interval, but the split points do not need to be the middle point.

For example, the following picture describe an interval tree on [1,6]:



Similar with segment tree, we can do some interval queries on interval tree. And we can define the time complexity of interval [l,r] as the number of vertices we need to visit when the query is about [l,r]. 

Formally, let S[l,r] be the set of vertices v on the interval tree which satisfy one of the following 2 conditions:
(1) v's interval is a subinterval of [l,r], but vv's father's interval is not. 
(2) At least one of v's decendants satisfies (1).

And then, we can define the time complexity of [l,r] as the size of S[l,r].

For example, in the picture, all the vertices in S[2,4] has been marked as blue. So the time complexity of [2,4] in this interval tree is 66. 

Now, given an interval tree on [1,n] and have q queries. Each query is a positive integer k, you need to find out the number of different intervals of which the time complexity is exactly k.

输入描述:

The input will consist of multiple test cases. Each case begins with two positive integer n and q. 

The second line contains n-1 integers, the split point of each non-leaf vertex, in the pre-order traversal. If vertex [l,r]'s split point is m, it's left child should be [l,m] and it's right child should be [m+1,r]. 

Then q lines follow. The i-th line of the following n lines is the integer k denoting the i-th query.

The input guarantees that l ≤ m < r, 1 ≤ n,q ≤ 105 , and 1 ≤ k ≤ 109  and the sum of n's and q's in all test cases will not exceed 500000.

输出描述:

For each query, output a single line with a single number, the answer.
示例1

输入

复制
6 7
5 1 3 2 4
1
2
3
4
5
6
7

输出

复制
1
2
2
3
6
4
3