포럼
문제 USACO0563

종이 쌓기

설명

농부 존은 종이 조각에 숫자 \(N\) (\(1\le N\le 300\))개를 적어 두었다. 각 \(i\in [1,N]\)에 대해 \(i\)번째 종이에는 숫자 \(a_i\) (\(1 \leq a_i \leq 9\))가 적혀 있다.

소들에게는 좋아하는 두 정수 \(A\)\(B\) (\(1\le A\le B< 10^{18}\))가 있고, \(Q\) (\(1\le Q\le 5\cdot 10^4\))개의 쿼리에 답해 주기를 원한다. \(i\)번째 쿼리에서 소들은 처음에 비어 있는 종이 더미를 유지하면서 종이 \(l_i\dots r_i\) (\(1\le l_i\le r_i\le N\))를 왼쪽에서 오른쪽으로 훑는다. 각 종이에 대해 더미의 맨 위에 놓거나, 맨 아래에 놓거나, 아무것도 하지 않는다. 끝나면 더미의 종이들을 위에서 아래로 읽어 하나의 정수를 만든다. 이 과정에서 소들이 선택할 수 있는 전체 \(3^{r_i-l_i+1}\)가지 방법 중, 소들이 읽는 정수가 \([A,B]\)(양 끝 포함)에 속하게 되는 방법의 수를 세고, 이를 \(10^9+7\)로 나눈 나머지를 출력한다.

출제자: Jesse Choe

제약

배점

  • 입력 2-3: \(B<100\)
  • 입력 4-5: \(A=B\)
  • 입력 6-13: 추가 제약이 없다.

출제자: Jesse Choe

입력 형식

첫째 줄에 공백으로 구분된 세 정수 \(N\), \(A\), \(B\)가 주어진다.

둘째 줄에 공백으로 구분된 \(N\)개의 숫자 \(a_1, a_2, \dots, a_N\)이 주어진다.

셋째 줄에 쿼리의 수인 정수 \(Q\)가 주어진다.

다음 \(Q\)개의 줄에 각각 공백으로 구분된 두 정수 \(l_i\)\(r_i\)가 주어진다.

출력 형식

각 쿼리에 대해 답을 한 줄에 하나씩 출력한다.

예제 1
입력
5 13 327
1 2 3 4 5
3
1 2
1 3
2 5
출력
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\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > February > Gold

태그

평가 및 의견

Piling Papers

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Piling Papers

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8