Today, the teacher told the tree-like array, Ben Konjac Konjac a little mengmengdongdong, but the basic template I still remember;
First, the principle:
Learn a tree-like array tonight ... So I'm going to summarize my understanding of it ...
This picture is on the internet casually looking for ...
Can be drawn from the graph:
C1=A1;
C2=C2+C1=A1+A2;
C3=A3;
C4=C4+C3+C2=A1+A2+A3+A4;
C5=A5;
C6=C6+C5=A5+A6;
C7=a7;
C8=c8+c7+c6+c4=a1+a2+a3+a4+a5+a6+a7+a8;
Top k items and:
S1=C1=A1;
S2=C2+C1=A1+A2;
S3=C3=A3;
S4=C4+C3+C2=A1+A2+A3+A4;
S5=A5;
S6=C6=C6+C5=A5+A6;
S7=c7=a7;
S8=c8+c7+c6+c4=a1+a2+a3+a4+a5+a6+a7+a8;
The above picture you may not understand, next is a good picture:
The edges of those numbers are binary, and we are considering from his binary;
1.lowbit
1 Long Long er (longlong k)2{3 return K &-K; 4 }
View Code
2. Update
1 void Add (longlong x,long long y)2{3 while (x<=N)4 {5 jie[x]+=y; 6 x+=er (x); 7 }8 }
View Code
3. Evaluation
1 Long LongQiuLong Longx)2 {3 Long Longtot=0;4 while(x!=0)5 {6tot+=Jie[x];7x-=er (x);8 }9 returntot;Ten}
View Code
Over
May 31, 2018 (tree-like array)