洛谷 2068_统计和_树状数组
来源:互联网 发布:高仿香港身份证淘宝 编辑:程序博客网 时间:2024/06/10 22:11
题目描述
给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区间的和。时间限制1秒。
思路
题目为单点修改加统计和,很容易想到用树状数组,套模板就可以了
#include <stdio.h>#include <iostream>#include <string>using namespace std;#define maxn 1000001int c[maxn];inline int read(){ int x=0, p=1; char ch=getchar(); while (ch < '0' || ch > '9'){if (ch == '-') p=-1; ch=getchar();} while (ch >= '0' && ch<='9'){x=(x << 1)+(x << 3)+ch-'0'; ch=getchar();} return x*p;}int n,m;int main(){ n=read(); m=read(); for (int k = 1; k <= m; k++) { char ch; cin >> ch; int x=read(), y=read(); if (ch == 'x') { for (int i = x; i <= n; i += i&(-i)) c[i] += y; } else { int l = 0, r = 0; for (int i = y; i > 0; i -= i&(-i)) r += c[i]; for (int i = x-1; i > 0; i -= i&(-i)) l += c[i]; printf("%d\n", r-l); } }}
1 1
- 洛谷 2068_统计和_树状数组
- 绕圈跑_纪中2930_树状数组统计
- 模板_树状数组(BIT)
- ACM_模板_树状数组
- ACM_模板_树状数组
- 洛谷P2268 统计和(树状数组)
- 统计和(树状数组)
- hdu 1166 _ 树状数组版
- hdu 1166_线段树&树状数组
- HDU_1394_线段树_树状数组
- LA4329乒乓比赛_树状数组
- 树状数组_应用的代码
- HDU_3450_Counting Sequences_树状数组_离散化
- codevs 1080_线段树练习_树状数组
- hoj 1867_经理的烦恼_树状数组
- USACO5.3 IDDFS_强连通_二维树状数组_斐蜀定理_矩形切割
- 树状数组,小结_(优雅的数据结构)
- 树状数组,小结_(优雅的数据结构)
- 把排序数组转换为高度最小的二叉搜索树
- jquery\json\ajax
- c++中输出小数格式控制(c++中怎么控制浮点型小数点后输出的位数)
- ubuntu live555测试
- pb实现增删改查
- 洛谷 2068_统计和_树状数组
- PowerShell 初探
- Retrofit2.0使用总结及注意事项
- T
- C++流的基础知识
- onActivityResult,startActivityForResult,setResult用法解决从后一个activity带参数跳转到前一个activity且不走前activity的onCre
- 面试技巧总结~
- c语言 根据字符串生成QR二维码 libqrencode库的使用
- hashmap源码学习整理