1 int c[maxn],n; 2 int lowbit(int x) 3 { 4 return x&(-x); 5 } 6 7 void update(int i,int val) 8 { 9 while(i<=n) 10 { 11 c[i] +=val; 12 i += lowbit(i); 13 } 14 } 15 int query(int i) 16 { 17 int sum = 0; 18 while (i > 0) 19 { 20 sum += c[i]; 21 i -= lowbit(i); 22 } 23 return sum; 24 }