Bzoj 5055: Film Mage--Tree stump array

Source: Internet
Author: User

DescriptionThere are still n perfect dimensions left in the universe after 1e9 major wars,now from the multiverse of the film Mage, want to steal one of the three dimensions for the great elders to renew the second,It is clear that he will be able to extend the time for the elders, the product of the energies of these three dimensions,But the current universe is not optimistic, the random stealing can cause the collapse of the dimension,So, he must steal these dimensions in reverse order, and in stealing,The energy of each stolen dimension must be strictly less than the energy he stole last time.since the film Mage lives in the multiverse, he can make all possible stealing schemes happen allTitle DescriptionBut he was not good at maths, so he found you to help him find a few seconds for the elderly,All you have to do is, in the given dimension sequence A,Find all the Ai*aj*ak that satisfy the i<j<k and Ai<aj<akthat is ∑ (A_i*a_j*a_k), requires i<j<k and A_i<a_j<a_kInputfirst row 1 number nsecond row n number a_iOutputa number which means that the elderly can be renewed for a few seconds because the elders are immortal,so can live a long time, may wish to take the answer to **19260817**Sample InputExample 1
4
1 2 3 4

Example Two
10
6 8 4 1 3 0 7 5 9 2Sample OutputSample Output 1
50
Sample Output 2
1737
Sample explanation
For example 1
There is an ordered column that satisfies the criteria
{1,2,3}--6
{1,2,4}--8
{1,3,4}--12
{2,3,4}--24
Ans=6+8+12+24=50
Data range
30% of Data n<=300
60% of Data n<=3000
100% of Data n<=300000
0<=a[i]<=2147483647———————————————————————————we can consider the answer to the two-tuple question first.so consider a single I with I as the end of the two group of the answer and is v[i]* than v[i] small x v[x] andso in the case of the two-tuple answer, it's easy to find the answer spicy .in fact, the answer to the two-tuple is thrown into a tree-like array.
#include <cstdio>#include<cstring>#include<algorithm>Const intm=1e6+7, mod=19260817;Charbuf[ One*m],*ptr=buf-1;intRead () {intans=0, f=1, c=*++ptr;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=*++ptr;}  while(c>='0'&&c<='9') {ans=ans*Ten+ (C-'0'); c=*++ptr;} returnans*F;}intN,k,ly,ans;intS1[m],s2[m],v[m],x[m];#defineLowbit (x) x&-xvoidInsintXintVintW[]) { while(x<=n) w[x]= (w[x]+v)%mod,x+=lowbit (x);}intQueryintXintW[]) {intsum=0; while(x) sum= (sum+w[x])%mod,x-=lowbit (x);returnsum;}intMain () {fread (buf,1,sizeof(BUF), stdin); N=read ();  for(intI=1; i<=n;i++) V[i]=read (), x[i]=V[i]; Std::sort (x+1, x+1+N);  for(intI=1; i<=n;i++) {k=std::lower_bound (x+1, x+1+n,v[i])-x; Ly=query (K-1, S1);        Ins (K,V[I],S1); Ans= (Ans+1ll*v[i]*query (k-1, s2)%mod)%MoD; INS (K,1ll*ly*v[i]%mod,s2); }printf ("%d\n", ans); return 0;}
View Code

Bzoj 5055: Film Mage--Tree stump 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.