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

19333번 - Subsequence Sum Queries 다국어

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

문제

You have an array $a$ containing $n$ integers and an integer $m$. You also have $q$ queries to answer. The $i$-th query is described as a pair of integers $(l_i, r_i)$. Your task is to calculate the number of such subsequences $a_{j_1}, a_{j_2}, \ldots, a_{j_k}$ that $l_i \le j_1 < j_2 < \ldots < j_k \le r_i$ and $(a_{j_1} + a_{j_2} + \ldots + a_{j_k}) \bmod m = 0$. In other words, you need to calculate the number of subsequences of subarray $[a_{l_i}, a_{l_i + 1}, \ldots, a_{r_i}]$ such that the sum of elements in each subsequence is divisible by $m$.

입력

The first line contains two integers $n$ and $m$: the number of elements in $a$ and the modulo (1ドル \le n \le 2 \cdot 10^5,ドル 1ドル \le m \le 20$).

The second line contains $n$ integers $a_i$: the elements of array $a$ (0ドル \le a_i \le 10^9$).

The third line contains one integer $q$: the number of queries (1ドル \le q \le 2 \cdot 10^5$).

Then $q$ lines follow. The $i$-th of these lines contains two integers $l_i$ and $r_i$ that describe the $i$-th query (1ドル \le l_i \le r_i \le n$).

출력

Print $q$ lines. The $i$-th of them must contain the answer for the $i$-th query. Queries are indexed in the order they are given in the input. Since the answers can be very large, print them modulo 10ドル^9 + 7$.

제한

예제 입력 1

4 3
5 1 3 2
4
1 2
1 3
1 4
2 4

예제 출력 1

2
4
6
4

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 8: Saratov SU Contest J번

Contest > Open Cup > 2017/2018 Season > Stage 13: Grand Prix of Saratov J번

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

출처

대학교 대회

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

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