페이지가 로드되지 않나요? 여기를 눌러보면 고쳐질 수도 있어요.
Placeholder

#5508

Piling Papers 1s 512MB

문제

Farmer John wrote down N (1≤N≤300) digits on pieces of paper. For each i∈[1,N], the ith piece of paper contains digit ai (1≤ai≤9).

 

The cows have two favorite integers A and B (1≤A≤B<1018), and would like you to answer Q (1≤Q≤5⋅104) queries. For the ith query, the cows will move left to right across papers li…ri (1≤li≤ri≤N), 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 3ri−li+1 ways for the cows to make choices during this process, count the number of ways that result in the cows reading an integer in [A,B] inclusive, and output this number modulo 109+7.​


입력

The first line contains three space-separated integers N, A, and B.

The second line contains N space-separated digits a1,a2,…,aN.

The third line contains an integer Q, the number of queries.

The next Q lines each contain two space-separated integers li and ri.​


출력

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


출처

USACO 2023 February Gold

로그인해야 코드를 작성할 수 있어요.