Under construction

Still being built. Things may change

V.I.P.

Time limit1sMemory limit1024 MB

Summary
Count the paths over active edges whose vertex weights strictly increase, answering each edge-flip query modulo 10^9+7.
Level

Hard8 of 10

Topics
Graph, Dynamic programming, Divide and conquer
Solved
No attempts yet

Problem

The complete graph GG has NN vertices. There are MM edge activation records and NN vertex weights. Initially, every edge is inactive. Each of the MM records is one of the following, and every edge is activated at most once among the MM records.

  • ii jj: Makes the edge connecting vertices ii and jj an active edge.

A path that visits vertices in increasing order of weight and does not use any inactive edge is called a V.I.P. (Very Important Path). For each query below, count the number of ***V.I.P.***s.

  • p qp\,q: Flips the activation state of the edge connecting vertices pp and qq. Output the number of ***V.I.P.***s in the changed graph, then restore the original activation state.

Input

The first line contains the number of vertices NN, the number of active edges MM, and the number of queries QQ, separated by spaces. (1≤N≤105;0≤M≤min⁡(N(N−1)2,2×105);1≤Q≤105)(1 \leq N \leq 10^5; 0 \leq M \leq \min(\frac{N(N-1)}{2}, 2 \times 10^5); 1 \leq Q \leq 10^5)

The second line contains the vertex weights w1,w2,…,wNw_1, w_2, \ldots, w_N, separated by spaces, where wiw_i is the weight of vertex ii. (1≤wi≤109)(1 \leq w_i \leq 10^9)

From line 3 to line M+2M + 2, line i+2i + 2 contains the two endpoints uiu_i and viv_i of the ii-th active edge, separated by a space. (1≤ui,vi≤N;ui≠vi)(1 \leq u_i, v_i \leq N; u_i \neq v_i)

From line M+3M + 3 to line M+Q+2M + Q + 2, line M+i+2M + i + 2 contains the ii-th query pip_i and qiq_i, separated by a space. (1≤pi,qi≤N;pi≠qi)(1 \leq p_i, q_i \leq N; p_i \neq q_i)

Output

For each query, output the number of ***V.I.P.***s. Since the answer can be very large, output it modulo 109+710^9+7.

Hint

In graph theory, a path is a sequence of adjacent vertices that visits each vertex at most once. A sequence of XX vertices P=v1,v2,⋯ ,vX−1,vXP = {v_1, v_2, \cdots, v_{X-1}, v_X} with X≥1X \geq 1 is a path if vi≠vjv_i \neq v_j whenever i≠ji \neq j, and for each 1≤i≤X−11 \leq i \leq X - 1 there is an edge whose endpoints are viv_i and vi+1v_{i+1} (with vi≠vi+1v_i \neq v_{i+1}).

An increasing sequence is a sequence aa of length nn that satisfies a1<a2<⋯<an−1<ana_1 < a_2 < \cdots < a_{n-1} < a_n.

Examples3

  1. Example 1

    Input
    3 2 2
    1 2 3
    1 2
    2 3
    1 2
    1 3
    
    Expected output
    4
    7
    
  2. Example 2

    Input
    4 0 5
    1 2 3 4
    1 2
    2 3
    3 4
    4 1
    1 3
    
    Expected output
    5
    5
    5
    5
    5
    
  3. Example 3

    Input
    3 2 1
    1 1 1
    1 2
    1 3
    1 2
    
    Expected output
    3