Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=5055
This problem ... Have to say, from the title to the surface can be seen a thick film method breath ... Gou......
Test instructions is the product of the statistical order ternary (which seems to be so called). There is a lower order version of the ternary group called Order pairs, in order to have a brother called reverse pairs. Since we can use the range tree array to handle the pairs of cis/reverse, we can also try to deal with the problem in the same way.
We can fix a[j] and ask for the rest of A[i] and a[k]. Ans=a[j]*sigma (A[i]*a[k])
So we have a sequence of three split into two order pairs, one is a[i]<a[j] and i<j, the other is a[j]<a[k] and j<k, and these two reverse is not interference, you can directly multiply the results.
So for each number, we find the sum of the numbers on the left that are smaller than it, and the sum of the numbers on the right that are larger than him, as l[i] and r[i]. So Ans=sigma (A[i]*l[i]*r[i])
#include <cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<ctime>#include<algorithm>#include<queue>#include<vector>#definell Long Long#defineMoD 19260817using namespacestd;inline ll Read () {ll tmp=0;Charf=1, c=GetChar (); while(c<'0'||'9'<C) {if(c=='-') f=-1; C=GetChar ();} while('0'<=c&&c<='9') {tmp=tmp*Ten+c-'0'; C=GetChar ();} returntmp*F;} ll c[300010];ll a[300010],id[300010],rk[300010];ll l[300010],r[300010];intN;BOOLCMP (ll X,ll y) {returna[x]<a[y];}voidAddintX,ll k) { while(x<=n) {c[x]+=k; x+=x& (-x);}} ll Getsum (intx) {ll sum=0; while(x) {sum+=c[x]; x-=x& (-X);}returnsum;}intMain () {inti; N=read (); for(i=1; i<=n;i++) A[i]=read (), id[i]=i; Sort (ID+1, id+n+1, CMP); rk[id[1]]=1; for(i=2; i<=n;i++) {Rk[id[i]]=rk[id[i-1]]; if(a[id[i]]>a[id[i-1]])++Rk[id[i]]; } for(i=1; i<=n;i++) c[i]=0; for(i=1; i<=n;i++) {L[i]=getsum (rk[i]-1)%mod; add (Rk[i],a[i]); } for(i=1; i<=n;i++) c[i]=0; ll sum=0; for(i=n;i;i--) {R[i]= (Sum-getsum (rk[i]))%mod; Add (Rk[i],a[i]); sum+=A[i]; } ll ans=0; for(i=1; i<=n;i++) ans= (Ans+l[i]*r[i]%mod*a[i])%MoD; printf ("%lld\n", ans); return 0;}
bzoj5055
"Bzoj5055" Film Mage (discretization + Tree Array)