Power Link

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

There are NN power generators and MM appliances. The iith generator produces a power of A_iA\_i. The jjth appliance is connected to a set of generator S_jS\_j and gets its energy from them. Let C_jC\_j be the number of generators in S_jS\_j.

The energy obtained by each appliance can be calculated with the following formula.

_1abC_jA_S_j\[a]A_S_j\[b]\displaystyle\sum\_{1 \le a \le b \le C\_j}{A\_{S\_{j}\[a]} \cdot A\_{S\_{j}\[b]}}

For example, let’s say an appliance gets its energy from 4 generators and each of them produces 1010, 55, 2020, and 55 of power, respectively. The energy obtained by this appliance is 105+1020+105+520+55+205=50+200+50+100+25+100=52510\cdot 5+10\cdot 20+10\cdot 5+5\cdot 20+5\cdot 5+20\cdot 5 = 50 + 200 + 50 + 100 + 25 + 100 = 525.

For the next QQ days, you will perform one of these two operations.

  1. Change the power produced by the iith generator to XX.
  2. Report the energy obtained by the jjth appliance.

For each operation of the second type, output the energy obtained by the jjth appliance.

입력

Input begins with a line containing two integers: NN MM (1N,M1000˜001 \le N, M \le 100\~000) representing the number of power generators and the number of appliances, respectively. The next line contains NN integers: A_iA\_i (1A_i100˜001 \le A\_i \le 10\~000) representing the power produced by the generators initially. The next MM lines each begins with an integer C_jC\_j (1C_jN1 \le C\_j \le N) representing the number of generators that are connected to the jjth appliance, followed by C_jC\_j integers: S_j\[k]S\_j\[k] (1S_j\[k]N1 \le S\_j\[k] \le N) representing the connected generators. For all jj, the generators in S_jS\_j are guaranteed to be unique. The sum of all C_jC\_j is not more than 2000˜00200\~000.

The next line contains an integer: QQ (1Q1000˜001 \le Q \le 100\~000) representing the number of days. The next QQ lines each contains one of the following input format representing the operation you should perform.

  • 1 ii XX (1iN1 \le i \le N; 1X100˜001 \le X \le 10\~000)
    Change the power produced by the iith generator to XX.
  • 2 jj (1jM1 \le j \le M)
    Output the energy obtained by the jjth appliance.

There will be at least one operation of the second type.

출력

For each operation of the second type in the same order as input, output in a line an integer representing the energy obtained by the jjth appliance.