
树状数组
nacrt
这个作者很懒,什么都没留下…
展开
-
nyoj116 士兵杀敌(二) (树状数组)
原题链接:nyoj116 士兵杀敌(二) 基本的树状数组的题,关于树状数组网上解析有很多,讲的也很详细,这里不做过多解释了,主要是下标按照位运算非常巧妙的储存 //树状数组:复杂度O(log n) #include using namespace std; const int MAX_N = 1000000 + 10; int N, M; int bit[MAX_N]; //bit[i]表原创 2017-04-28 17:08:45 · 1242 阅读 · 0 评论 -
poj2299 Ultra-QuickSort/nyoj117(树状数组,归并排序)
原题链接:Ultra-QuickSort 题意:给出n个数,求用冒泡排序排成从小到大的序列所交换的次数 思路:本题要求的是逆次序用冒泡排序时间内是O(n^2)会超时,可以用归并排序或树状数组 //算法复杂度:O(nlogn) //用树状数组实现,因为a[i]的值范围较大,要对其进行离散化后在用树状数组维护 #include #include using namespace std;原创 2017-04-24 15:18:19 · 1164 阅读 · 0 评论 -
poj3468 A Simple Problem with Integers(用线段树和树状数组实现)
原题链接:A Simple Problem with Integers 题意:给定一个数列A[1],A[2]...A[N]以及Q个操作,按顺序行这些操作,操作分为两种: 1、给出l,r,x 对A[l],A[l+1]...A[r]同时加上x 2、给出l,r 求A[l]+A[l+1]+...+A[r]的值 Sample Input 10 5 1 2 3 4 5 6 7 8 9 1原创 2017-04-14 15:04:01 · 1287 阅读 · 0 评论 -
nyoj123 士兵杀敌(四) 树状数组之插线问点
原题链接:nyoj123 士兵杀敌(四) 用线段树超时了,用树状数组过了 #include using namespace std; #define lowbit(i) i & -i const int MAX_M = 1000000 + 1; int T, M; int bit[MAX_M]; void add(int i, int x){ while(i <= M){ bit[原创 2017-05-03 11:35:53 · 2492 阅读 · 0 评论