Subsequence Sum Queries
Time limit2sMemory limit256 MB
For each query range [l, r] of an array with m at most 20, count the subsequences whose sum is divisible by m, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Divide and conquer, Dynamic programming
- Solved
- No attempts yet
Problem
You are given an array of integers and an integer . You must answer queries. The -th query is a pair of integers . For each query, count the subsequences with whose sum is divisible by . In other words, count the subsequences of the subarray whose element sum is a multiple of .
Input
The first line contains two integers and (, ).
The second line contains integers ().
The third line contains one integer ().
Each of the next lines contains two integers and ().
Output
Print lines. The -th line must contain the answer to the -th query, in the order the queries are given. Print each answer modulo .