Hdu 2492 tree-like array Ping pong

Source: Internet
Author: User

1#include <iostream>2#include <cstdio>3#include <cstring>4 #defineMAXN 1000055 #defineM 200056 typedef __int64 LL;7 using namespacestd;8 LL N,max_num;9 LL S[M],A[M],B[M],C[MAXN];Ten ll Lowbit (ll x) { One     returnx& (-x); A } - ll sum (ll x) { -LL ret =0; the      while(X >0){ -RET + =C[x]; -X-=lowbit (x); -     } +     returnret; - } + voidAdd (ll x, ll D) { A      while(x<=max_num) { atC[X] + =D; -X + =lowbit (x); -     } - } - intMain () { - LL T,i,j,ans; inCin>>T; -      while(t--){ toCin>>N; +Max_num =0; -          for(i =1; I <= N; i++){ thescanf"%i64d",&s[i]); *             if(s[i]>max_num) $Max_num =S[i];Panax Notoginseng         } -Memset (c,0,sizeof(c)); the          for(i =1; I <= N; i++){ +Add (S[i],1); AA[i] = SUM (s[i]-1); the         } +Memset (c,0,sizeof(c)); -          for(i = n; i>0; i--){ $Add (S[i],1); $B[i] = SUM (s[i]-1); -         } -Ans =0; the          for(i =1; I <= N; i++){ -             //cout<<a[i]<< "" <<b[i]<<endl;WuyiAns = ans+a[i]* (N-i-b[i]) + (i-a[i]-1)*B[i]; the         } -cout<<ans<<Endl; Wu     } -     return 0; About}

Hdu 2492 tree-like array Ping pong

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.