Score : 525 points
问题描述
对于两个整数集合 A 和 B,满足 A∩B=∅,我们定义 f(A,B) 如下:
- 定义序列 C=(C1,C2,…,C∣A∣+∣B∣) 包含集合 A∪B 的所有元素,并按升序排列。
- 取 k1,k2,…,k∣A∣ 使得 A={Ck1,Ck2,…,Ck∣A∣}。然后令 f(A,B)=i=1∑∣A∣ki。
例如,若 A={1,3} 且 B={2,8},则 C=(1,2,3,8),所以 A={C1,C3};因此,f(A,B)=1+3=4。
我们有 N 个包含 M 个整数的集合 S1,S2,…,SN,其中每个集合为 Si={Ai,1,Ai,2,…,Ai,M}。这里保证了任意 i=j 时,Si∩Sj=∅。
求 1≤i<j≤N∑f(Si,Sj)。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For two sets of integers, A and B, such that A∩B=∅, we define f(A,B) as follows.
- Let C=(C1,C2,…,C∣A∣+∣B∣) be a sequence consisting of the elements of A∪B, sorted in ascending order.
- Take k1,k2,…,k∣A∣ such that A={Ck1,Ck2,…,Ck∣A∣}. Then, let f(A,B)=i=1∑∣A∣ki.
For example, if A={1,3} and B={2,8}, then C=(1,2,3,8), so A={C1,C3}; thus, f(A,B)=1+3=4.
We have N sets of integers, S1,S2…,SN, each of which has M elements. For each i (1≤i≤N), Si={Ai,1,Ai,2,…,Ai,M}. Here, it is guaranteed that Si∩Sj=∅ (i=j).
Find 1≤i<j≤N∑f(Si,Sj).
Constraints
- 1≤N≤104
- 1≤M≤102
- 1≤Ai,j≤109
- If i1=i2 or j1=j2, then Ai1,j1=Ai2,j2.
- All input values are integers.
The input is given from Standard Input in the following format:
N M
A1,1 A1,2 … A1,M
⋮
AN,1 AN,2 … AN,M
Output
Print the answer as an integer.
3 2
1 3
2 8
4 6
Sample Output 1
12
S1 and S2 respectively coincide with A and B exemplified in the problem statement, and f(S1,S2)=1+3=4. Since f(S1,S3)=1+2=3 and f(S2,S3)=1+4=5, the answer is 4+3+5=12.
1 1
306
Sample Output 2
0
4 4
155374934 164163676 576823355 954291757
797829355 404011431 353195922 138996221
191890310 782177068 818008580 384836991
160449218 545531545 840594328 501899080
Sample Output 3
102
update @ 2024/3/10 08:39:40