二维数组数组板子,和一维基本类似: void update(int x,int y,int z) { // cout<<"?"; for(int i=x;i<=n;i+=lowbit(i)) for(int j=y;j<=n;j+=lowbit(j)) c[i][j]+=z; } int getsum(int x,int y) { int sum = 0 ; for(int i=x;i>=1;i-=lowbit(i)) for(int j=y;...
int number(int x) { return x&-x; } void insert(int x,int y,int z) { int i,j; for(i=x;i<=N;i+=number(i))//到最大的范围N,而不是n. for(j=y;j<=N;j+=number(j)) c[i][j]+=z; } int sum(int x,int y) { int i,j,su=0; for(i=x;i>0;i-=number(i)) for...
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Submission(s): 785 Accepted Submission(s): 335 Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make the problem easier,we considerate the sky is a two...
一步一步更新所有区间的最大值//有距离限制,即到达某一位置时,j可能过大导致越界,所以对与每个i,有区间属于:[1,n-(2^j-1)]//则j的受限范围为:j≤n⇔j≤lg[n],其中lg[n]表示n关于底数2的对数向下取整,可以递推求得。