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

树状数组的特殊形式

时间:2016-11-16 07:46:41      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:return   最大   lowbit   color   数组   span   blog   div   style   

 1 //用树状数组维护前i项最值
 2 
 3 map<int,int> m;//用map可以突破下标过大导致的空间限制
 4 
 5 int lowbit(int x)
 6 {
 7     return x&-x;
 8 }
 9 
10 void upd(int idx,int val)
11 {
12     while(idx<maxn)
13     {
14         m[idx]=max(val,m[idx]);
15         idx+=lowbit(idx);
16     }
17 }
18 
19 int query(int idx)
20 {
21     int ans=0;
22     while(idx>0)
23     {
24         ans=max(ans,m[idx]);
25         idx-=(idx&(-idx));
26     }
27     return ans;
28 }

算是这场CF的最大收获吧

树状数组的特殊形式

标签:return   最大   lowbit   color   数组   span   blog   div   style   

原文地址:http://www.cnblogs.com/Just--Do--It/p/6068017.html

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