树状数组
多一些不为什么的坚持
qq:1216161552
展开
-
搞懂树状数组
来自 程序猿__int64Ago 的博客 引用请注明出处:http://blog.csdn.net/int64ago/article/details/7429868 写下这个标题,其实心里还是没底的,与其说是写博帖,不如说是做总结。第一个接触树状数组还是两年前,用什么语言来形容当时的感觉呢?……太神奇了!真的,无法表达出那种感觉,她是那么的优雅,10行不到的代码转载 2017-07-23 12:19:29 · 229 阅读 · 0 评论 -
【数据结构】树状数组笔记
树状数组(Binary Indexed Tree, BIT) 转自大牛 柳婼 の blog https://www.liuchuo.net/archives/2268 本质上是按照二分对数组进行分组,维护和查询都是O(lgn)的复杂度 树状数组与线段树:树状数组和线段树很像,但能用树状数组解决的问题,基本上都能用线段树解决,而线段树能解决的树状数组不一定能解决。相比较而言,树转载 2017-07-23 12:22:35 · 362 阅读 · 0 评论 -
51Nod 1081 子段求和(数组/树状数组)
题目链接 数组: #include #include #include #include #include #include using namespace std; long long t[50001]={0}; int n; void add(int x,long long v){ while(x<=n){ t[x]+=v; x+=x&-x; } } long long sum原创 2017-09-03 20:19:20 · 197 阅读 · 0 评论 -
51Nod 1019 逆序数(树状数组/归并)
题目链接 看了很多博客都说把数据离散化。我也不是很懂 树状数组基本的做法浪费空间。存储不下 我感觉所谓的离散化就是根据数据的大小排序,然后根据下标重新给数组一个顺序 举个例子把: 2 5 6 3 num 1 2 3 4 id 根据num排序之后 1 3 5 6 num 1 4 2 3 id 因为现在id就代表数据的位置 为id附上编号 1 3 5 6 num 1 4原创 2017-09-01 23:54:27 · 249 阅读 · 0 评论 -
HDU DNA Sorting (树状数组求逆序对)
这题就是求逆序对然后根据逆序对大小排序 暴力可解! 我选择的是树状数组,这题如果变种,数据过大,或者需要离散化,暴力就不好解决了 离散化树状数组 这题浪费挺长时间的,主要是t数组忘记清0.。导致后面的数据全部错误 #include #include #include #include #include #include #include using namespace st原创 2017-09-24 14:25:15 · 333 阅读 · 0 评论 -
1098: 树状数组2(破坏公路)
题目描述 题目描述: 在太平洋中心有一个圆形小岛,沿着小岛的海岸线分布着n个小镇,编号分别为1,2,3~~n;小镇i-1、小镇i、小镇i+1是相邻的(当然小镇n与小镇1相邻)。相邻小镇之间存在一条公路,公路也有编号,公路i连接小镇i和小镇i+1,公路n连接小镇n和小镇1.现在对小岛有m个操作,操作有两种: 询问操作:1 x y 代表小镇x到小镇y是否联通,联通输出1,否则输出原创 2017-09-27 21:16:34 · 508 阅读 · 0 评论 -
51Nod 1874 字符串排序 逆序对
暴力也可以 #include #include #include #include #include #include #include #include #include using namespace std; typedef struct node{ char a[55]; int index; int len; }node; int tree[50]={0}; i原创 2017-12-10 20:07:31 · 276 阅读 · 0 评论 -
Poj 1195 Mobile phones(二维树状数组求子矩阵和)
Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 22317 Accepted: 10375 Description Suppose that the fourth generation mobile phone base stations in the Tampere area oper...原创 2018-08-26 12:18:15 · 266 阅读 · 0 评论