Morty Buys Groceries
Time limit6sMemory limit1024 MB
Given n product costs, count ordered sequences of k products whose total cost lies between l and r for each query, modulo 786433.
- Level
Medium7 of 10
- Topics
- Math, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Rick and Morty went to a store. As you may have figured out, Rick loves giving Morty all kinds of tasks, and this time is no exception. He needs Morty to count the ways to buy products. The store has products in total, and the cost of the -th product is . Rick will give Morty two numbers and a total of times. For each pair, Morty must say how many ways there are to buy products whose total cost is at least and at most .
A purchase is written as a set of indices , where is the number of the product bought -th. Two purchases and are different if there is an index such that . So and are two different ways to buy. Also, one product can be bought any number of times.
Input
The first line contains three integers , , (, ). The second line contains integers , the costs of the products (). Each of the next lines contains two integers and ().
Output
Print the answers to Rick's queries, one per line. Since the answer can be very large, print it modulo .