#P9129. [USACO23FEB] Piling Papers G
[USACO23FEB] Piling Papers G
题目描述
Farmer John wrote down digits on pieces of paper. For each , the ith piece of paper contains digit .
The cows have two favorite integers and , and would like you to answer queries. For the -th query, the cows will move left to right across papers , maintaining an initially empty pile of papers. For each paper, they will either add it to the top of the pile, to the bottom of the pile, or neither. In the end, they will read the papers in the pile from top to bottom, forming an integer. Over all ways for the cows to make choices during this process, count the number of ways that result in the cows reading an integer in inclusive, and output this number modulo .
输入格式
The first line contains three space-separated integers , and .
The second line contains space-separated digits .
The third line contains an integer , the number of queries.
The next lines each contain two space-separated integers and .
输出格式
For each query, a single line containing the answer.
题目大意
给定长度为 的整数序列 ,和整数区间 ,有 次询问,每次询问给出 。每次询问开始,你有一个空串 ,你可以正序对 进行操作,操作有三种:,,或者什么也不做,求 的取值在 的不同的操作方案数,对 取模。
5 13 327
1 2 3 4 5
3
1 2
1 3
2 5
2
18
34
提示
Explanation for Sample 1
For the first query, there are nine ways Bessie can stack papers when reading the interval :
- Bessie can ignore then ignore , getting .
- Bessie can ignore then add to the top of the stack, getting .
- Bessie can ignore then add to the bottom of the stack, getting .
- Bessie can add to the top of the stack then ignore , getting .
- Bessie can add to the top of the stack then add to the top of the stack, getting .
- Bessie can add to the top of the stack then add to the bottom of the stack, getting .
- Bessie can add to the bottom of the stack then ignore , getting .
- Bessie can add to the bottom of the stack then add to the top of the stack, getting .
- Bessie can add to the bottom of the stack then add to the bottom of the stack, getting .
Only the ways that give yield a number between and , so the answer is .
SCORING
- Inputs :
- Inputs :
- Inputs : No additional constraints.