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

用扩展过的树状数组过的这道题,树状数组部分只用了1600.008个K的内存

Posted by AllwaysDead at 2009-02-14 21:44:06 on Problem 3368
inline int Max(int a,int b){return a>b?a:b;}
inline int Lowbit(int a){return a&-a;}
int tree1[200001],tree2[200001],Big;
void addvalue(int key,int v){key+=100000;
     int m;
     if (key%2)m=(tree2[key]+=v);else m=(tree1[key]+=v);
     for (int j=key;j<Big;j+=Lowbit(j+1))tree1[j]=Max(tree1[j],m);
     for (int j=key;j;j-=Lowbit(j))tree2[j]=Max(tree2[j],m);
}
int findMax(int l,int r){l+=100000;r+=100000;
    int j,s;s=-2100000000;
    for (j=r;j-Lowbit(j+1)+1>=l;j-=Lowbit(j+1))s=Max(s,tree1[j]);
    if (l)for (j=l;j+Lowbit(j)-1<=r;j+=Lowbit(j))s=Max(s,tree2[j]);
    return s;
}
void iniTree(){
     Big=200001;
     memset(tree1,0,sizeof(tree1));
     memset(tree2,0,sizeof(tree2));
}

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