树状数组
来源:互联网 发布:r创建数据集 dataframe 编辑:程序博客网 时间:2024/06/06 03:03
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>const int MAXN = 500000 + 5;int c[MAXN];int n,m;inline int lowbit(int x){return x&(-x);}inline void swap(int &a,int &b){a^=b;b^=a;a^=b;}void sum(int x,int y){if(x>y)swap(x,y);x--;int l=0,r=0;for(;x>0;x-=lowbit(x))l+=c[x];for(;y>0;y-=lowbit(y))r+=c[y];printf("%d\n",r-l);}void add(int x,int val){for(;x<=n;x+=lowbit(x))c[x]+=val;}int main(){memset(c,0,sizeof(c));scanf("%d",&n);for(int i=1;i<=n;i++){int b;scanf("%d",&b);add(i,b);}scanf("%d",&m);while(m--){int x,y,z;scanf("%d%d%d",&x,&y,&z);if(x==1)add(y,z);else sum(y,z);}return 0;}
0 0
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 如何刷百度搜索下拉框进行营销引流?
- Django学习笔记(一)
- STM32启动文件
- iOS界面约束第三方框架对比
- 获取网络文本查看器--HTML源码
- 树状数组
- C语言如何获得变量的物理地址以及简单的写时拷贝测试
- relation "public.***" contains more than "max_fsm_pages" pages with useful free space
- Spring的AOP详解
- 详解HttpURLConnection
- 深入浅出RxJava(二:操作符)
- Linux内存中的Cache真的能被回收吗?
- bzoj 3626 LCA
- 隐私政策