Test instructions: n groups, each group has a number of values, for each group in different two groups to select a value and greater than K method.
Solution: N * cnt[n] <= 1000*100 = 100000, that is, up to 10^5 individuals, so enumerate each value x, ask him how many of those groups are greater than k-x, how many more than k-x can first ask how many of the number is less than or equal to K-x, and then a total reduction can be. You can use a tree-like array.
All the numbers are stored in a tree array, and then each time the number of a group is enumerated, the number of the group is removed.
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#defineLLL __int64using namespacestd;#defineN 101107intc[n],num[1006][104],b[2*n],t[1007];intLowbit (intx) {returnx&-x;}voidModifyintXintval) { while(x <= NTen) {C[x]+=Val; X+=lowbit (x); }}intGetsum (intx) { intres =0; while(X >0) {res+=C[x]; X-=lowbit (x); } returnRes;}intMain () {intt,n,k,m,i,j; CIN>>T; while(t--) {scanf ("%d%d",&n,&k); intCNT =0; for(i=1; i<=n;i++) {scanf ("%d", &num[i][0]); for(j=1; j<=num[i][0];j++) scanf ("%d", &num[i][j]), b[++cnt] =Num[i][j]; Sort (Num[i]+1, num[i]+num[i][0]+1); } t[n+1] =0; for(i=n;i>=1; i--) T[i]= t[i+1] + num[i][0]; Sort (b+1, b+cnt+1); Memset (c,0,sizeof(c)); for(i=1; i<=n;i++) { for(j=1; j<=num[i][0];j++) { intid = lower_bound (b +1, b+cnt+1, Num[i][j])-b; Modify (ID,1); }} lll sum=0; for(i=1; i<=n;i++) { for(j=1; j<=num[i][0];j++) { intid = lower_bound (b +1, b+cnt+1, Num[i][j])-b; Modify (ID,-1); } for(j=1; j<=num[i][0];j++) { intnow =Num[i][j],id; if(K-now <0) id =0; Else{ID= Lower_bound (b +1, b+cnt+1, K-now)-b; if(B[id]! = K-now) id--; } Sum+ = t[i+1]-getsum (ID); }} cout<<sum<<Endl; } return 0;}View Code
HDU 5101 Select--discretization + Tree Array