QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#9649. problem

统计

Given $n$ intervals $[l_i, r_i]$ and a constant $k$.

For two intervals $[l, r]$ and $[l', r']$, define the function $f([l, r], [l', r'])$ as the length of the intersection of intervals $[l, r]$ and $[l', r']$.

More formally, we have: $$ f([l, r], [l', r']) = \begin{cases} 0 & \text{if } r' < l \, \text{or} \, l' > r \\ \min(r, r') - \max(l, l') + 1 & \text{otherwise} \end{cases} $$

Given $m$ queries, each providing an interval $[L, R]$, you need to calculate $\sum_{i=1}^n f([L, R], [l_i, r_i])^k$, modulo $10^9 + 7$.

Input

The first line contains three integers $n, k, m$.

The next $n$ lines each contain two integers $l_i, r_i$.

The next $m$ lines each contain two integers $L, R$.

Output

Output $m$ lines, each containing an integer representing $\sum_{i=1}^n f([L, R], [l_i, r_i])^k$, modulo $10^9 + 7$.

Examples

Input 1

3 1 2
1 1
1 2
1 3
1 2
1 3

Output 1

5
6

Note 1

For the first query, the answer is $f([1, 1], [1, 2]) + f([1, 2], [1, 2]) + f([1, 3], [1, 2]) = 1 + 2 + 2 = 5$.

For the second query, the answer is $f([1, 1], [1, 3]) + f([1, 2], [1, 3]) + f([1, 3], [1, 3]) = 1 + 2 + 3 = 6$.

Input 2

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

Output 2

38
16
26
26

Note 2

For the first query, the answer is $f([1, 4], [1, 4])^2 + f([2, 3], [1, 4])^2 + f([1, 3], [1, 4])^2 + f([2, 4], [1, 4])^2 = 16 + 4 + 9 + 9 = 38$.

Constraints

For all data, it is guaranteed that: $1 \le n, m \le 10^5$, $1 \le k \le 14$, $1 \le l_i \le r_i \le n$, $1 \le L \le R \le n$.

Test Case ID $n, m \le$ $k$ $r_i, R \le$ Special Property
$1 \sim 2$ $2 \times 10^3$ $\le 14$ $n$ None
$3 \sim 4$ $10^5$ $=1$ $n$ None
$5 \sim 10$ $10^5$ $=2$ $n$ None
$11 \sim 12$ $10^5$ $\le 8$ $\min{n, 600}$ None
$13 \sim 20$ $10^5$ $\le 8$ $n$ A
$21 \sim 23$ $10^5$ $\le 8$ $n$ None
$24 \sim 25$ $10^5$ $\le 14$ $n$ None

Special Property A: It is guaranteed that for all given intervals, any two intervals are either equal or do not contain each other.

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.