Influential Groups
Practice
5 (1 votes)
Combinatorics
Math
Medium
Problem
62% Success 216 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \(\lfloor \frac{S}{2} \rfloor\) people should be less than that of Ram. Note: \(\lfloor x \rfloor \) 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 \(\le\) N \(\le\) 105

1 \(\le\) Q \(\le\) N

1 \(\le\) Influential Value \(\le\) 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.

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
18 votes
Tags:
CombinatoricsMathMedium
Points:30
7 votes
Tags:
CombinatoricsNumber TheoryBasics of CombinatoricsAlgorithmsModulus ArithmeticMath
Points:30
5 votes
Tags:
Modular arithmeticCombinatoricsNumber theoryPrime FactorizationBasics of CombinatoricsAlgorithmsModular exponentiationMath