uvalive 2191(BIT)
来源:互联网 发布:蒙科立蒙古文网络平台 编辑:程序博客网 时间:2024/06/08 17:02
题意:给出n个数字,操作有修改和输出区间和。
题解:树状数组模板水题。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 200005;int C[N], n;char str[10];int lowbit(int x) { return x & (-x);}int Sum(int x) { int ret = 0; while (x > 0) { ret += C[x]; x -= lowbit(x); } return ret;}void Add(int x, int d) { while (x <= n) { C[x] += d; x += lowbit(x); }}int main() { int cas = 0; while (scanf("%d", &n) == 1 && n) { memset(C, 0, sizeof(C)); int x, a, b; for (int i = 1; i <= n; i++) { scanf("%d", &x); Add(i, x); } if (cas) printf("\n"); printf("Case %d:\n", ++cas); while (scanf("%s", str) && str[0] != 'E') { scanf("%d%d", &a, &b); if (str[0] == 'M') printf("%d\n", Sum(b) - Sum(a - 1)); else { x = Sum(a) - Sum(a - 1); int temp = b - x; Add(a, temp); } } } return 0;}
0 0
- uvalive 2191(BIT)
- uvalive 4329(BIT)
- uvalive 5902(BIT)
- Bit String Reordering UVALive
- UVALive 6832Bit String Reordering
- Uvalive 6832 Bit String Reordering
- UVALive 6832Bit String Reordering
- [2012长春]Bit Magic UVALive
- UVALive 6832Bit String Reordering (模拟)
- UVALive - 6832 Bit String Reordering (找规律)
- UVALive 3565 Bit Compressor (搜索)
- UVALive 3675 Sorted bit sequence(数位dp+二分)
- UvaLive-2191-Potentiometers
- UVALive 2191 Potentiometers
- UVALive - 2191 Potentiometers
- UVALive
- UVALive
- UVALive
- NYOJ 17 单调递增最长子序列
- 字符串计数
- Java学习之路:不走弯路,就是捷径
- bzoj-3052 糖果公园
- hdu 5364 Distribution money
- uvalive 2191(BIT)
- [leetcode] N-Queens
- 约瑟夫环 不同密码
- CSS 进阶篇
- 对协程的理解
- JdbcTemplate的使用
- 【JCC技术】JCC功能演示
- hdu1698
- HDU 1200 To and Fro