hdu 1166
来源:互联网 发布:养老院软件 编辑:程序博客网 时间:2024/06/06 07:47
#include <stdio.h>#include <string.h>#define maxn 500005int p[maxn], c[maxn], n;char ask[15];int lowbit(int x){return x & (-x);}void update(int x, int num){while(x <= n){c[x] += num;x += lowbit(x);}}int getSum(int x){int s = 0;while(x > 0){s += c[x];x -= lowbit(x);}return s;}int main(){int t, i, k, x, y;scanf("%d", &t);k = 1;while(t--){printf("Case %d:\n", k++);scanf("%d", &n);memset(c, 0, sizeof(c));for(i = 1;i <= n;i++){scanf("%d", &p[i]);update(i, p[i]);}while(1){scanf("%s", ask);if(!strcmp(ask, "Add")){scanf("%d %d", &x, &y);update(x, y);}else if(!strcmp(ask, "Sub")){scanf("%d %d", &x, &y);update(x, -y);}else if(!strcmp(ask, "Query")){scanf("%d %d", &x, &y);printf("%d\n", getSum(y) - getSum(x - 1));}else if(!strcmp(ask, "End")) break;}}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
- OGG笔记(一)-基本操作
- 配置远程连接mysql数据库 Connect to remote mysql database
- UI_UIScrollView/UIpageControl
- 使用vector容器创建二维数组
- 7月7日随感
- hdu 1166
- Java 程序流程控制和函数
- Java NIO vs. IO
- final/finalize/finally的区别
- 构造方法、类方法、类的复合
- 【总览】我的技术博客
- android基础_数据库的创建
- Android设备开机动画的原理和修改方式
- Python中的单/双下划线