Analysis: Because it does not add up to more than 1e6, so up to 1000+ a different number
Practice: Discretization is good.
#include <cstdio>#include<iostream>#include<ctime>#include<vector>#include<cmath>#include<map>#include<queue>#include<algorithm>#include<cstring>using namespaceStd;typedefLong LongLL;Const intn=1e5+5;Const intinf=0x3f3f3f3f;Const intmod=1e9+7;intA[n],b[n],c[n],k1[n],k2[n];intMain () {intn,m; while(~SCANF ("%d%d",&n,&m)) { for(intI=1; i<=n;++i) {scanf ("%d",&A[i]); C[i]=A[i]; } sort (A+1, A +1+N); intCnt1=unique (A +1, A +1+n)-a-1; memset (K1,0,sizeof(K1)); for(intI=1; i<=n;++i) { ++k1[lower_bound (A +1, A +1+cnt1,c[i])-a]; } for(intI=1; i<=m;++i) {scanf ("%d",&B[i]); C[i]=B[i]; } sort (b+1, B +1+m); intCnt2=unique (b +1, B +1+M)-b-1; memset (K2,0,sizeof(K2)); for(intI=1; i<=m;++i) { ++k2[lower_bound (b +1, B +1+cnt2,c[i])-b]; } LL ret=0; for(intI=1; i<=cnt1;++i) { for(intj=1; j<=cnt2;++j) {LL tmp=SQRT (ABS (a[i]-b[j])); RET+=1ll*k1[i]*k2[j]*tmp; }} printf ("%i64d\n", ret); } return 0;}
View Code
XTUOJ1250 Super Fast Fourier Transform violence