hdu 4970 树状数组 “改段求段”
来源:互联网 发布:框架户和端口户的返点 编辑:程序博客网 时间:2024/06/07 02:49
题意:塔防。给1--n,给出m个塔,每个塔有攻击力,给出k个怪兽的位子和血量,问有几只可以到达n点。
今天刚刚复习了树状数组,就碰到这个题,区间更新、区间求和类型。第三类树状数组可以斩。
注意一下大数即可。
#include<iostream>#include<cstdio>#include<cstring>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<m;i++) { scanf("%d%d%d",&l,&r,&c); add_b(r,c);add_b(l-1,-c); add_c(r,c); add_c(l-1,-c); } int k; scanf("%d",&k); int counted=0; __int64 xi,hi; for(int i=1;i<=k;i++) { scanf("%I64d%I64d",&hi,&xi); if(hi>sum(n)-sum(xi-1)){counted++;} } printf("%d\n",counted); } return 0;}
1 0
- hdu 4970 树状数组 “改段求段”
- HDU-4970 Killing Monsters (树状数组)
- HDU 1394 树状数组
- 树状数组 hdu
- hdu 1166 树状数组
- HDU 2838 树状数组
- hdu 2492【树状数组】
- hdu 3015【树状数组】
- hdu 3874 树状数组
- hdu 3874(树状数组)
- hdu 3890 树状数组
- 【树状数组】hdu 2852
- 【树状数组】hdu 4000
- HDU 4046 树状数组
- hdu 1166(树状数组)
- HDU-3887-树状数组
- hdu 4358树状数组
- hdu 3333 树状数组
- Sublime Text 2 安装 zen coding (Emmet)
- SpringMVC利用return new ModelAndView(new RedirectView("xxx.do"), Map map)重定向传递多参数
- FusionCharts在Java中的基本使用
- Android系统开发(1)——GCC编译器的编译和安装过程
- 最短路的Bellman-Ford算法 【判断有无负权环】
- hdu 4970 树状数组 “改段求段”
- 几何算法学习
- Android LayoutInflater详解
- 实现数组复制
- Hibernate3注解
- hdu 2203亲和串
- scala ActorSyetem异常
- iOS UIWebView键盘处理
- Docker秘籍 之 创建史上最小Docker容器