设为首页 加入收藏

TOP

hdu 4970 树状数组 “改段求段”
2015-07-20 17:51:35 来源: 作者: 【 】 浏览:1
Tags:hdu 4970 段求段

题意:塔防。给1--n,给出m个塔,每个塔有攻击力,给出k个怪兽的位子和血量,问有几只可以到达n点。

今天刚刚复习了树状数组,就碰到这个题,区间更新、区间求和类型。第三类树状数组可以斩。

注意一下大数即可。

#include
  
   
#include
   
     #include
    
      using namespace std; __int64 tree1[100010],tree2[100010]; int n,m; void add_b(int x,int c) { while(x>0) { tree1[x]+=c; x-=(x&(-x)); } } __int64 sum_b(int x) { // if(x==0)return 0; __int64 res=0; while(x<=n) { res+=tree1[x]; x+=(x&(-x)); } return res; } void add_c(int x,int c) { if(x<1)return ; int tx=x; while(x<=n) { tree2[x]+=c*tx; x+=(x&(-x)); } } __int64 sum_c(int x) { __int64 res=0; while(x>0) { res+=tree2[x]; x-=(x&(-x)); } return res; } __int64 inline sum(int x) { if(x>=1) return sum_b(x)*x+sum_c(x-1); else return 0; } int main() { while(~scanf("%d",&n)&&n) { scanf("%d",&m); memset(tree1,0,sizeof(tree1)); memset(tree2,0,sizeof(tree2)); int l,r,c; for(int i=0;i
     
      sum(n)-sum(xi-1)){counted++;} } printf("%d\n",counted); } return 0; } 
     
    
   
  



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇LRU的C++的简单实现 下一篇Hdu 3699 Aragorn's Story (..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: