"Bzoj5055" Film Mage (discretization + Tree Array)

Source: Internet
Author: User

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'&LT;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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.