hdu 1166 赤裸裸的树状数组
2011-09-06 10:54
381 查看
题目没啥说的,赤裸裸的树状数组
/* * hdu1166/win.cpp * Created on: 2011-9-6 * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MAXN = 50100; int N, M; int array[MAXN]; inline int lowbit(int x) { return x & (x ^ (x - 1)); } int sum(int n) { int ret = 0; for(int i = n; i > 0; i -= lowbit(i)) { ret += array[i]; } return ret; } void update(int index, int value) { for (int i = index; i <= N; i += lowbit(i)) { array[i] += value; } } void work(); int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); #endif work(); return 0; } void work() { char op[20]; int a, b, T, temp; scanf("%d", &T); for (int t = 1; t <= T; t++) { printf("Case %d:\n", t); scanf("%d", &N); memset(array, 0, sizeof(array)); for (int i = 1; i <= N; i++) { scanf("%d", &temp); update(i, temp); } while (scanf("%s", op) == 1) { if (strcmp(op, "End") == 0) { break; } scanf("%d%d", &a, &b); if (strcmp(op, "Query") == 0) { printf("%d\n", sum(b) - sum(a - 1)); } else if (strcmp(op, "Add") == 0) { update(a, b); } else { update(a, -b); } } } }
相关文章推荐
- HDU 1166 树状数组
- HDU1166——树状数组模板
- HDU 1166 敌兵布阵 (线段树 & 树状数组)
- hdu hdoj 1166 敌兵布阵 树状数组
- HDU 1166 敌兵布阵 数据结构+树状数组+(单点更新区间求和)
- hdu 1166 树状数组
- HDU 1166 敌兵布阵 树状数组
- HDU 1166 敌兵布阵(线段树,树状数组)
- hdu 1166(线段树或者树状数组)
- hdu 1166 树状数组(模板) 更改点值+求区间和
- HDU 1166 敌兵布阵(区间求和&(线段树|树状数组))
- HDU-1166 敌兵布阵 线段树|树状数组
- HDU 1166 敌兵布阵(线段树 or 树状数组)
- hdu 1166 敌兵布阵(线段树,树状数组)
- hdu 1166 敌兵布阵 树状数组
- hdu-1166 敌兵布阵 树状数组
- [ACM_数据结构] HDU 1166 敌兵布阵 线段树 或 树状数组
- hdu 1166 敌兵布阵(线段树、树状数组)
- hdu-1166 敌兵布阵 (线段树或树状数组)
- HDU 1166 树状数组