luogu#P10268. 符卡对决

符卡对决

Background

Reimu is having a spell card duel with Marisa.

Card

永夜の报い,Pixiv76062895,author: minusT. Please contact for removal.

Problem Description

Reimu has nn spell cards. Each card has a power value. For the ii-th card, its power value is aia_i. Now she wants to choose two spell cards and use them. Reimu finds that if she plays two spell cards i,ji, j at the same time, the damage dealt by these two spell cards will be ai×aja_i\times a_j.

There are power conflicts among these spell cards, and Reimu will tell you the compatibility of the spell cards. More specifically, there are mm relations among these spell cards, and each relation indicates that two spell cards are compatible. Note that if spell cards i,ji, j are compatible and spell cards j,kj, k are compatible, then spell cards i,ki, k are also compatible. If the two spell cards played are not compatible, then the damage they deal is 00.

She is curious about what impact compatibility among spell cards will have, so she will ask you qq queries. Each time she gives you a pair of positive integers l,rl, r, meaning that only the relations with indices in the interval [l,r][l, r] will take effect.

Reimu does not want to bully Marisa too badly, so she will randomly pick two different spell cards from all spell cards to play. She wants to know, for each query, the expected damage modulo 109+710^9 + 7.

Input Format

The first line contains three integers n,m,qn, m, q, representing the total number of spell cards, the total number of relations among the spell cards, and the number of queries.

The next line contains nn positive integers, where the ii-th integer is aia_i.

The next mm lines each contain two positive integers ui,viu_i, v_i, indicating that spell card uiu_i and spell card viv_i are compatible.

The next qq lines each contain two positive integers li,ril_i, r_i, indicating the interval [li,ri][l_i, r_i] of relation indices in Reimu's query.

Output Format

Output qq lines in total. The ii-th line contains one integer, representing, in the ii-th query, the expected damage when randomly choosing two different spell cards, taken modulo 109+710^9 + 7.

4 4 4
5 8 2 7 
3 1
1 4
3 2
1 4
2 4
1 2
2 3
3 3
500000012
833333349
500000012
666666674
14 16 15
1 2 7 3 2 4 6 2 5 7 2 4 3 3 
5 12
2 9
2 10
7 10
6 12
12 3
11 1
4 8
1 13
6 8
6 10
4 1
1 10
12 11
3 5
9 7
14 14
2 16
5 6
2 3
5 10
1 6
5 16
13 15
1 2
3 7
3 4
14 14
3 7
6 7
11 14
318681321
263736277
868131875
725274731
32967035
384615390
637362648
780219786
967032974
406593411
208791211
318681321
406593411
945054952
681318687

Hint

Sample 1 Explanation

For the third query, only the two pairs (1,4)(1, 4) and (2,3)(2, 3) of spell cards are compatible.

If the chosen spell cards are (1,2)(1, 2), then they are not compatible and the damage is 00. The probability of this case is 16\dfrac16.

If the chosen spell cards are (1,3)(1, 3), then they are not compatible and the damage is 00. The probability of this case is 16\dfrac16.

If the chosen spell cards are (1,4)(1, 4), they are compatible, and the damage is a1×a4=35a_1\times a_4 = 35. The probability of this case is 16\dfrac16.

If the chosen spell cards are (2,3)(2, 3), they are compatible, and the damage is a2×a3=16a_2\times a_3 = 16. The probability of this case is 16\dfrac16.

If the chosen spell cards are (2,4)(2, 4), then they are not compatible and the damage is 00. The probability of this case is 16\dfrac16.

And so on. In the end, the expected value is 172\dfrac{17}{2}, which equals 500000012500000012 modulo 109+710^9 + 7.

Constraints

This problem uses bundled testdata.

For all testdata, $1\le n, q\le 10^5, 1\le m\le 2n, 1\le a_i\le 10^9, 1\le l_i\le r_i\le m, 1\le u_i, v_i\le n$.

For different subtasks, we use the following settings:

Subtask ID nn qq Special Property Score
00 300\le300 None 55
11 2000\le 2000 A 1010
22 B 55
33 None 1010
44 30000\le 30000
55 50000\le 50000 A
66 B
77 None 1515
88 105\le 10^5 2525
  • Special Property A: It is guaranteed that ui=1,vi=i+1,m=n1u_i = 1, v_i = i + 1, m = n - 1.
  • Special Property B: It is guaranteed that li=1l_i = 1.

Translated by ChatGPT 5