#P3600. 随机数生成器

    ID: 2650 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp洛谷原创O2优化期望洛谷月赛

随机数生成器

Description

sol developed a magical random number system that can automatically generate true random numbers from environmental noise.

Now sol plans to generate nn integers in [1,x][1,x], namely a1,...,ana_1, ..., a_n, and then handle some queries.

There are qq queries. For each query ii with parameters lil_i and rir_i, sol will compute minlijriaj\min_{l_i \leq j \leq r_i} a_j (the minimum value of the numbers in the array aa whose indices are between lil_i and rir_i).

Finally, the test result is the maximum among the results of these queries.

sol has conducted many experiments. Now he wants to ask you for the expected value of the test result, modulo 666623333666623333.

Input Format

The first line contains three integers n,x,qn, x, q.

Each of the next qq lines contains two integers lil_i and rir_i.

Output Format

Output a single integer, the answer.

2 2 1
1 2
499967501
6 6 6
1 3
2 4
3 5
4 6
5 6
3 4
88571635

Hint

Tip: The result of a fraction ab\frac{a}{b} modulo 666623333666623333 is a×b666623331 mod 666623333a\times b^{666623331}~\mod~666623333.

For 10%10\% of the testdata, n,x,q6n,x,q \leq 6.

For another 20%20\% of the testdata, q=1q=1.

For 50%50\% of the testdata, n,x,q300n,x,q \leq 300.

For 70%70\% of the testdata, n,x,q800n,x,q \leq 800.

For 100%100\% of the testdata, 1n,x,q20001 \leq n,x,q \leq 2000, and for each ii, 1lirin1 \leq l_i \leq r_i \leq n.

Translated by ChatGPT 5