Logo
(追記) (追記ここまで)

27845번 - Piling Papers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB112393132.979%

문제

Farmer John wrote down $N$ (1ドル\le N\le 300$) digits on pieces of paper. For each $i\in [1,N],ドル the $i$th piece of paper contains digit $a_i$ (1ドル \leq a_i \leq 9$).

The cows have two favorite integers $A$ and $B$ (1ドル\le A\le B< 10^{18}$), and would like you to answer $Q$ (1ドル\le Q\le 5\cdot 10^4$) queries. For the $i$th query, the cows will move left to right across papers $l_i\dots r_i$ (1ドル\le l_i\le r_i\le 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 3ドル^{r_i-l_i+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 10ドル^9+7$.

입력

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

The second line contains $N$ space-separated digits $a_1, a_2, \dots, a_N$.

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

The next $Q$ lines each contain two space-separated integers $l_i$ and $r_i$.

출력

For each query, a single line containing the answer.

제한

예제 입력 1

5 13 327
1 2 3 4 5
3
1 2
1 3
2 5

예제 출력 1

2
18
34

For the first query, there are nine ways Bessie can stack papers when reading the interval $[1, 2]$:

  • Bessie can ignore 1ドル$ then ignore 2ドル,ドル getting 0ドル$.
  • Bessie can ignore 1ドル$ then add 2ドル$ to the top of the stack, getting 2ドル$.
  • Bessie can ignore 1ドル$ then add 2ドル$ to the bottom of the stack, getting 2ドル$.
  • Bessie can add 1ドル$ to the top of the stack then ignore 2ドル,ドル getting 1ドル$.
  • Bessie can add 1ドル$ to the top of the stack then add 2ドル$ to the top of the stack, getting 21ドル$.
  • Bessie can add 1ドル$ to the top of the stack then add 2ドル$ to the bottom of the stack, getting 12ドル$.
  • Bessie can add 1ドル$ to the bottom of the stack then ignore 2ドル,ドル getting 1ドル$.
  • Bessie can add 1ドル$ to the bottom of the stack then add 2ドル$ to the top of the stack, getting 21ドル$.
  • Bessie can add 1ドル$ to the bottom of the stack then add 2ドル$ to the bottom of the stack, getting 12ドル$.

Only the 2ドル$ ways that give 21ドル$ yield a number between 13ドル$ and 327ドル,ドル so the answer is 2ドル$.

힌트

출처

Olympiad > USA Computing Olympiad > 2022-2023 Season > USACO 2023 February Contest > Gold 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /