码迷,mamicode.com
首页 > 编程语言 > 详细

树状数组模版

时间:2020-02-28 01:36:38      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:font   数组   +=   col   span   void   class   turn   style   

 1 int lowbit(int x) {
 2    return x & -x;
 3 }
 4 
 5 void add(int x, int y) {
 6    for (int i = x; i <= n; i += lowbit(i)) 
 7     c[i] += y;
 8 }
 9 
10 int ask(int x) {
11    int res = 0;
12    for (int i = x; i; i -= lowbit(i)) 
13     res += c[i];
14    return res;
15 }

 

树状数组模版

标签:font   数组   +=   col   span   void   class   turn   style   

原文地址:https://www.cnblogs.com/hhyx/p/12375354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!