QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 512 MB 總分: 100

#9646. Subset Sum

统计

There are $n$ items, where item $i$ has two attributes $a_i$ and $b_i$. For a set of items $S$, define $f(S)$ as the answer to the following problem:

  • For each item $i \in S$, choose one of the three values $0, a_i, b_i$ such that the sum of the chosen values for all items is a multiple of $m$. Find the number of such ways.

Define the set of all items as $S = \{1, 2, \dots, n\}$. There are $q$ queries. Each query provides four positive integers $1 \le l_1 \le r_1 < l_2 \le r_2 \le n$. Calculate: $$ \sum_{l_1 \le i \le r_1} \sum_{l_2 \le j \le r_2} f(S \setminus \{i, j\}) $$ The answer should be taken modulo $10^9 + 7$.

Input

The first line contains three positive integers $n, m, q$.

The next $n$ lines each contain two non-negative integers $a_i, b_i$.

The next $q$ lines each contain four positive integers $l_1, r_1, l_2, r_2$, representing a query.

Output

Output $q$ lines, each containing a non-negative integer representing the answer modulo $10^9 + 7$.

Examples

Input 1

6 10 5
2 3
7 1
1 4
8 1
2 5
8 9
1 2 3 4
1 1 2 2
1 1 5 5
1 3 4 6
1 5 6 6

Output 1

33
9
11
80
37

Constraints

For all data:

  • $1 \le n \le 10^4$
  • $2 \le m \le 200$
  • $1 \le q \le 10^6$
  • $0 \le a_i, b_i < m$ ($1 \le i \le n$)
Subtask $n \le$ $m \le$ Special Property Score
$1$ $100$ $AB$ $5$
$2$ $500$ $AB$ $5$
$3$ $20$ $AB$ $20$
$4$ $150$ $A$ $15$
$5$ $B$ $15$
$6$ $C$ $10$
$7$ $l_1 = r_1, l_2 = r_2$ $5$
$8$ $25$

Special Property $A$: Each query is chosen randomly from all valid $(l_1, r_1, l_2, r_2)$ tuples.

Special Property $B$: $q \le 10^5$.

Special Property $C$: For each item $i$, $a_i = b_i$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.