Xjtuoj Wmq's Team (tree-like array to find K-yuan reverse order)

Source: Internet
Author: User

Topic Link: http://oj.xjtuacm.com/problem/14/"Analysis" two yuan in reverse order should be asked, you can use a tree-like array. This problem requires K-yuan, we can be regarded as two yuan. We first seek two yuan reverse logarithm,

And then for each number you can find the number of smaller numbers behind this number. And then we add a dollar, now sweep to A[i], then in the tree array, for those larger than his number of the inverse of the logarithm + = on the inverse logarithm of a dollar a[i].

#include <bits/stdc++.h>#defineMet (b) memset (a,b,sizeof a)#definePB Push_back#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1#defineLowbit (x) (x& (×))using namespaceStd;typedefLong Longll;ll MoD= 1e9+7;Const intn=2e4+ -;Const intm=n*n+Ten;intN,m,k,a[n];ll Tre[n],ans1[n],ans2[n];voidAddintx,ll s) {     while(x<=N) {Tre[x]+=s; TRE[X]%=MoD; X+=lowbit (x); }}ll Sum (intx) {LL ret=0;  while(x>0) {ret+=Tre[x]; RET%=MoD; X-=lowbit (x); }    returnret;}intMain () {intu,v; intT; scanf ("%d",&T);  while(t--) {scanf ("%d%d",&n,&k);  for(intI=1; i<=n;i++) scanf ("%d", &a[i]), ans2[i]=1; if(m==1) {printf ("%d\n", n);Continue; }         for(intt=2; t<=k;t++){             for(intI=1; i<=n;i++) ans1[i]=ans2[i],ans2[i]=tre[i]=0;  for(inti=n;i>=1; i--) {Ans2[a[i]]=Sum (A[i]);            Add (A[i],ans1[a[i]]); }} ll ans=0;  for(intI=1; i<=n;i++) ans= (Ans+ans2[i])%MoD; printf ("%lld\n", ans); }    return 0;}

Xjtuoj Wmq's Team (tree-like array to find K-yuan reverse order)

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.