HDU 1166 (敌兵布阵)
来源:互联网 发布:gps端口修改器 编辑:程序博客网 时间:2024/06/13 22:32
线段树,更新,区间求和。
#include <iostream>#include <cstdio>#include <cmath>#include <string>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define maxx 50005int sum[maxx<<2];int n;void pushplus(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void build(int l,int r,int rt){ if(l==r) { scanf("%d",&sum[rt]); return; } int m=(l+r)>>1; build(lson); build(rson); pushplus(rt);}int query(int left,int right,int l,int r,int rt){ if(left<=l&&right>=r) return sum[rt]; int m=(l+r)>>1; int ans=0; if(left<=m) { ans+=query(left,right,lson); } if(right>m) { ans+=query(left,right,rson); } return ans;}void update(int p,int add,int l,int r,int rt){ if(l==r) { sum[rt]=sum[rt]+add; return ; } int m=(l+r)>>1; if(p<=m) update(p,add,lson); else update(p,add,rson); pushplus(rt);}int main(){ int t; string s; int a,b; scanf("%d",&t); for(int i=1;i<=t;i++) { printf("Case %d:\n",i); scanf("%d",&n); build(1,n,1); while(cin>>s&&s[0]!='E') { scanf("%d%d",&a,&b); if(s[0]=='Q') printf("%d\n",query(a,b,1,n,1)); if(s[0]=='A') update(a,b,1,n,1); else if(s[0]=='S') update(a,-b,1,n,1); } } return 0;}
0 0
- HDU 1166 敌兵布阵
- HDU 1166 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- HDU 1166 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- HDU 1166 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- HDU 1166 敌兵布阵
- HDU 1166 - 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- hdu 1166 敌兵布阵
- sharepoint获取server端绝对路径的方法
- 安装wget1.16
- Json解析字符串的类型总结--IOS
- java泛型
- 将UIButton的SEL转成block
- HDU 1166 (敌兵布阵)
- hdu 1800 Flying to the Mars(字典树||map||hash)
- Android存储方式的选择
- GRE写作必备句型
- 算法八:Bellman-Ford算法及优化
- 去掉listview的分割线和分割线的颜色,高度的设置
- poj 3046 数蚂蚁 dp
- VS 演进
- 实现iphone风格的对话框