#P5629. 【AFOI-19】区间与除法

    ID: 4515 远端评测题 2000~3000ms 256MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>线段树st表,稀疏表字典树,Trie 树

【AFOI-19】区间与除法

Description

Define the operation opop as: divide the current number by dd and take the floor.

SY now has mm “original numbers”. If a number can become an “original number” after performing the opop operation some number of times (including 00 times), then this number can be wiped out by that “original number”. Note that “original numbers” will not be consumed.

Now SY asks you: for an interval [l,r][l,r], under the condition that you wipe out as many numbers as possible, what is the minimum number of “original numbers” needed?

Input Format

The first line contains 44 numbers n,m,d,qn,m,d,q, representing the number of elements in the sequence {a}\{a\}, the number of “original numbers” SY has, the parameter of the opop operation, and the number of queries.

The second line contains the sequence {a}\{a\}, i.e., the numbers that need to be wiped out.

The third line contains mm “original numbers”.

The next qq lines each contain two numbers ll and rr, indicating the query interval [l,r][l,r].

Output Format

In the order of the queries, output one integer per line as the answer.

2 3 3 3
0 20
6 6 6
1 1
2 2
1 2

0
1
1

6 3 3 3
6 5 10 15 19 7
2 5 10
1 6
1 4
4 6

3
3
2

Hint

Sample Explanation:

Sample 1: 2020 can become 66 after one opop operation (divide by 33 and take the floor), but 00 cannot become 66 after any number of opop operations.

So for interval [1,1][1,1], at most 00 numbers can be wiped out; under the condition of wiping out the maximum number of numbers, the minimum number of “original numbers” needed is 00. For intervals [1,2][1,2] and [2,2][2,2], at most 11 number can be wiped out; under that condition, the minimum number of “original numbers” needed is 11.

Sample 2: 22 can wipe out {6,19,7}\{6,19,7\}, 55 can wipe out {5,15}\{5,15\}, and 1010 can wipe out {10}\{10\}. So for intervals [1,6][1,6] and [1,4][1,4], you can use all “original numbers” to wipe out everything. For interval [4,6][4,6], you can use 2,52,5 to wipe out everything.

Constraints:

For 30%30\% of the testdata: n100,m10,d=2,q10n\le100,m\leq10, d=2, q\le 10.

For 100%100\% of the testdata: $n\le5\times 10^{5},m\leq60,2\leq d\leq10,q\le10^{6},0\le a_i,b_i< 2^{63}$.

Special property: the testdata is constructed.

Translated by ChatGPT 5