Influential Groups

5

1 votes
Combinatorics, Math, Medium
Problem

The village of Bellandur is unique. Each person here has a unique value attached to him. We call this values as Influential Value of that person. Influential Value is a positive integer that assigned to every integer denotes how influential that person is.

Ram is a Mathematician who lives in Bellandur. Ram has a big ego problem. He could only have a conversation in those groups where his Influential Value is greater than half of the people in the group i.e. if the group size is S then the influential value of at-least S2 people should be less than that of Ram. Note: x denotes the floor function.

Ram has figured out the Influential Value of every person in Bellandur. He wants to determine how many groups exist where his ego doesn't get hurt. He is trying to find out such groups for different Influential powers. Ram doesn't like wasting time so he only considers those Influential Values that are present in Bellandur. Since the count of such groups could be very large he is considering values modulo 109+7.

Input:

First line contains N denoting the number of people living in Bellandur and Q that denotes the number of query Ram has. Second line contains space-separated distinct integers that indicate the Influential value of every people living in Bellandur. Third line contains Q-space separated integers where each value denotes an Influential value for which Ram tries to find out the required groups.

Output:

Output Q integers that are the required count of groups for every query.

Constraints:

1  N  105

1 Q  N

1  Influential Value  109

Note:

The query value will be from the input array itself and is necessary to include that value in the final groups for that query.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For Query-1, the only possible scenario is to form a lone group {1} , hence only 1 group can be formed.

For Query-3, the possible valid groups are {2} , {1, 2} , {1, 2, 4} , {1, 2, 6}, {1, 2, 8} , {1, 2, 9}

Editor Image

?