#P8640. [蓝桥杯 2016 国 A] 圆圈舞

[蓝桥杯 2016 国 A] 圆圈舞

Problem Description

Warm spring sunshine shines on the earth, and this is the happiest time for the little animals on the grassland. The little animals held a ball on the grassland to celebrate this wonderful time.

The most important part of the ball is dancing in circles. nn little animals hold hands and form a big circle, dancing with the music. During the dance, the animals may change their formation. Their way of changing is: animal A lets go of its right hand, animal B lets go of its left hand, then animal A and B hold hands, and the two hands that were released correspondingly (if any) also hold hands.

For example, suppose there are 1010 little animals forming a circle in order. The right hand of animal 11 holds the left hand of animal 22, the right hand of animal 22 holds the left hand of animal 33, and so on. Finally, the right hand of animal 1010 holds the left hand of animal 11. If the formation is changed through animals 22 and 88, then the right hand of animal 22 holds the left hand of animal 88, and correspondingly the left hand of animal 33 holds the right hand of animal 77, forming two circles 1-2-8-9-10 and 3-4-5-6-7. If now the formation is changed through animals 22 and 66, then one big circle 1-2-6-7-3-4-5-8-9-10 will be formed. Note that if at this time the formation is changed through animals 11 and 22, then the formation will not change, because after the right hand of animal 11 and the left hand of animal 22 are released, they are held together again.

During the dance, each animal ii has a happiness value HiH_i and a moving value FiF_i.

If two animals are in the same circle, their happiness values will affect each other and produce happiness energy. If two animals i,j(ij)i, j(i\neq j) are in the same circle of size tt, and animal ii is at the pp-th position to the right of animal jj (the 11-st position to the right of animal jj is the animal held by the right hand of animal jj, and the 22-nd position is the animal held by the right hand of the animal at the 11-st position, and so on), then the happiness energy produced is (tp)×Hj×Fi(t-p)\times H_j\times F_i. During the dance, the animals’ happiness values and moving values may change.

At the beginning of the dance, all animals form one circle in increasing order of their indices, and the animal at the ii-th position to the right of animal nn is exactly animal ii. Now, given the process of formation changes and the process of changes in happiness values and moving values, find the sum of the happiness energy produced by all animals after each formation change.

Constraints

Input Format

The first line contains an integer nn, representing the number of animals.

In the next nn lines, each line contains two integers HiH_i and FiF_i separated by a space, giving the happiness value and moving value of each animal in order of indices.

The next line contains an integer mm, representing the number of changes of formation, happiness values, and moving values.

In the next mm lines, each line contains three integers kk, pp, and qq separated by spaces. When k=1k=1, it means the animals changed formation through animal pp and animal qq. When k=2k=2, it means the happiness value of animal pp becomes qq. When k=3k=3, it means the moving value of animal pp becomes qq.

Output Format

Output mm lines. Each line contains one integer, representing the sum of energy produced by all animals after each change.

The answer may be very large. You need to output the remainder of the answer modulo 10000000071000000007 (i.e. 109+710^9+7).

10
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
9
1 2 8
1 2 6
2 8 10
3 5 10
1 1 2
1 2 1
2 5 5
1 4 8
1 4 5
100
450
855
1341
1341
811
923
338
923

Hint

For 20%20\% of the testdata, 2n,m1002\le n,m\le100.

For 30%30\% of the testdata, 2n,m10002\le n,m\le1000.

For another 20%20\% of the testdata, there are only operations with k=1k=1, and both HiH_i and FiF_i are 11.

For another 20%20\% of the testdata, there are only operations with k=1k=1 or 22, and all FiF_i are 11.

For 100%100\% of the testdata, 2n,m1052\le n,m\le10^5, 0Hi,Fi1090\le H_i,F_i\le10^9, 1k31\le k\le3. When k=1k=1, 1p,qn1\le p,q\le n and pqp\neq q. When k=2k=2 or 33, 1pn1\le p\le n and 0q1090\le q\le10^9.

Translated by ChatGPT 5