Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

树状数组是有希望代替线段树的。。。至少这题是这样的。

Posted by fanhqme at 2009-03-01 17:36:39 on Problem 2761
树状数组颂

树状数组,圣洁美丽,
二进制光芒照大地.
我们心中充满热情
来到你的圣殿里,
你的魔力能使人们
消除一切TLE.
在你光辉照耀下面,
人们AC成兄弟.

int tree[100000];
void iniTree(){memset(tree,0,sizeof(tree));}
inline int Lowbit(int a){return a&-a;}
void ins(int a,int b){//若b==1,插入元素a。若b==-1,删除元素a
     while (a<N){
           tree[a]+=b;
           a+=Lowbit(a+1);
     }
}
int findKth(int k){//寻找第k大的元素
    int i,j;
    i=0;
    while (1){
          j=0;
          while (i<N && tree[i]<k)i+=(j=Lowbit(i+1));
          i-=j;
          k-=tree[i];
          if (!k)break;
          ++i;
          if (Lowbit(i+1)!=1)break;
    }
    return i;
}
推荐:
http://www.wiskey86.cn/wordpress/?p=26
不过是用线段树写的。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator