树状数组
来源:互联网 发布:nba比赛球员数据 编辑:程序博客网 时间:2024/06/18 18:38
一维
#include<cstdio>#include<iostream>#define N 10000using namespace std;int n,a[N],c[N];int lowbit(int x){ return x&(-x);}void modify(int k,int d){ int t=k; while (t<=n){ c[t]+=d; t+=lowbit(t); }}int query(int k){ int ans=0,t=k; while (t){ ans+=c[t]; t-=lowbit(t); } return ans;}int main(){ cin >> n; for (int i=1;i<=n;i++) scanf("%d",&a[i]); return 0;}
二维
#include<cstdio>#include<iostream>#define N 10000using namespace std;int n,a[N][N],c[N][N];int lowbit(int x){ return x&(-x);}void modify(int k,int l,int d){ int x=k,y; while (x<=n) { y=l; while (y<=n) { c[x][y]+=d; y+=lowbit(y); } x+=lowbit(x); }}int query(int k,int l){ int ans=0,x=k,y; while(x) { y=l; while(y) { ans+=c[x][y]; y-=lowbit(y); } x-=lowbit(x); } return ans;}int main(){ cin >> n; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%d",&a[i][j]); return 0;}
0 0
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- 树状数组
- MAC 新建文本文档
- 架构师需要了解的Paxos原理、历程及实战
- 对封装、继承、多态、抽象的理解
- 解决Apache 2.4.9提示You don’t have permission to access / on this server.
- Java初级学习小记-重载和this关键字及static关键字
- 树状数组
- processBitmap - java.lang.IllegalStateException and java.io.FileNotFoundException
- 【JZOJ4833】【NOIP2016提高A组集训第3场10.31】Mahjong
- ntp-实现时间同步
- Shiro相关知识点
- Tomcat内存溢出报java.lang.OutOfMemoryError: PermGen space错误的解决方案
- 洛谷 P3406 海底高铁
- Laravel 5 User Model not found
- 二叉树的三种遍历方式