
ACM——线段树、树状数组
懵懂记忆
这个作者很懒,什么都没留下…
展开
-
UESTC 838 —— 母仪天下(树状数组模板)
树状数组: 1、Add(x,d):让A[x]增加d 2、query(L,R):计算区间[L,R]中所有元素的和 Code:#include #include using namespace std; int C[100010],n; int lowbit(int &x) { return x&(-x); } int sum(int x) { int ret =原创 2015-04-01 22:59:33 · 510 阅读 · 0 评论 -
UESTC 839——东风不与周郎便(线段树区间修改模板)
解题思路:线段树区间修改,详见代码。 Code:#include #include using namespace std; typedef long long LL; #define MAX 110000 LL n,m; LL _Sum,_Max,_Min; struct Tree { LL L,R; LL Sum,add,Min,Max; }trees[MAX*3]; vo原创 2015-04-01 20:36:20 · 1017 阅读 · 0 评论 -
2014 UESTC Training for Data Structures—— E - 休生伤杜景死惊开
解题思路:树状数组。假设x[i]是数值为i的数的个数,所以求的比q[i]小的数就有x[i-1]+x[i-2]+…..+x[2]+x[1],于是就可以用树状数组来写了,从头到尾扫一遍,对每个数都算一下前面比他小的数的个数即x[q[i]-1]+x[q[i]-2]+…….x[2]+x[1],然后从后往前扫一遍,对每个数计算后面比他小的数的数量。然后相同位置计算得到的两个数相乘,再求和就可以了。详见代码:原创 2015-04-08 22:20:59 · 733 阅读 · 0 评论