#P9491. ZHY 的集合

ZHY 的集合

Problem Description

The time limit was changed to 1 s after the contest.

ZHY once again misread the problem during the contest.

For two sets A,BA,B each of size xx, satisfying AB=A\cap B=\varnothing (the empty set), ZHY defines f(A,B)f(A,B) as follows:

  • Let C=ABC=A\cup B. Sort the elements in CC in increasing order.

  • f(A,B)=i=1xCif(A,B)=\displaystyle \sum_{i=1}^x C_i.

Now, ZHY has nn sets S1,S2,,SnS_1,S_2,\cdots,S_n, each of size mm. He wants to know the value of $\displaystyle \sum_{i=1}^n\sum_{j=i + 1}^n f(S_i,S_j)$.

However, ZHY is not satisfied with this. So he performs qq modification operations. In each operation, one set is given again. After each modification, output the answer once, i.e., $\displaystyle \sum_{i=1}^n\sum_{j=i + 1}^n f(S_i,S_j)$. It is guaranteed that at any time, all elements within any set are pairwise distinct, and the intersection of any two sets is empty.

Input Format

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

Lines 22 to n+1n+1 each contain mm integers describing the sets S1,S2,,SnS_1,S_2,\cdots,S_n. The mm numbers on line i+1i+1 are the mm integers in set SiS_i.

Then follow qq lines. In each line, the first integer is xx, indicating the index of the set to be modified. The following mm numbers are the mm integers in the new SxS_x.

Output Format

The first line contains one integer, the initial answer.

Then output qq lines, each containing one integer, the answer after each modification.

3 2 2
1 3
2 6
4 8
1 3 5
2 7 9
13
18
26

Hint

This problem uses bundled testdata.

Subtaskid\mathrm{Subtask} \kern{2pt} \mathrm{id} nn mm qq Score
00 100\le 100 10\le 10 77
11 100\le 100 100\le 100 1111
22 103\le 10^3 103\le 10^3 77
33 104\le 10^4 =0=0 1515
44 103\le 10^3 2727
55 104\le 10^4 3333

For all data, 0n,q1040 \le n, q \le 10^4, 1m1001 \le m \le 100, 1Si,j1091 \le S_{i,j} \le 10^9. It is guaranteed that at any time, for $\forall i\in [1,n],\kern{2pt}j \in [1,m],\kern{2pt}i' \in[1,n],\kern{2pt}j'\in [1,m]$, if iii \ne i' or jjj \ne j', then Si,jSi,jS_{i,j} \ne S_{i',j'}。

Translated by ChatGPT 5