#include <iostream> #include <cstdlib> using namespace std; class BinaryIndexedTree { private: int *mem; int capacity; public: BinaryIndexedTree (int n) { ) { capacity = ; return; } capacity = n; mem = ]; ; i<=capacity; i++) mem[i] = ; } ~B…
感谢http://www.cnblogs.com/xudong-bupt/p/3484080.html 树状数组(BIT)是能够完成下述操作的数据结构: 给定一初始值全为零的数列a1,a2a,a3...,an 1.给定i,计算a1+a2+...+ai 2.给定i和x,执行ai+=x BIT的结构: 数组bit[N] bit[1]=C1=A1;bit[2]=C2=C1+A2; BIT就是使用数组来维护上面所说的部分和 以1结尾的1,3,5,7长度为1 以1个0结尾的2,6长度为2 以两个0结尾的4…
Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4948    Accepted Submission(s): 1746 Problem Description After inventing Turing Tree, 3xian always felt boring when solving problems a…
                                                          Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 27470   Accepted: 8140 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will gr…
题意:给一个数组,每次查询输出区间内不重复数字的和. 这是3xian教主的题. 用前缀和的思想可以轻易求得区间的和,但是对于重复数字这点很难处理.在线很难下手,考虑离线处理. 将所有查询区间从右端点由小到大排序,遍历数组中的每个数字,每次将该数字上次出现位置的值在树状数组中改为0,再记录当前位置,在树状数组中修改为当前的数值.这样可以保证在接下来的查询中该数字只出现了一次.这是贪心的思想,只保留最可能被以后区间查询的位置.如果当前位置是某个查询区间的右端点,这时候就可以查询了.最后再根据查询区间…
Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22613 Accepted: 6875 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been car…
题目传送门 题目大意: 给定一颗根节点为1的树,有两种操作,第一种操作是将与根节点距离为L的节点权值全部加上val,第二个操作是查询以x为根节点的子树的权重. 思路: 思考后发现,以dfs序建立树状数组,方便查询,不方便修改,以bfs序建立树状数组,方便修改,不方便查询. 在计算子树权重的时候发现,如果我能算出 所有层 属于这棵子树的  点数*对应层需要加上的val,那么就得到了这棵树的总权重.但是显然暴力统计点数会超时,于是我们把用一个分块的想法,对于一层来说,如果这层的总点数小于块的大小,就…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22131   Accepted: 6715 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…
There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been carefully nurturing the big apple tree. The tree has N forks which are connected by branches. Kaka numbers…
先做一次dfs求得每个节点为根的子树在树状数组中编号的起始值和结束值,再树状数组做区间查询 与单点更新. #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<, INF =  * N]; , ; } inline ;     ;i-=lowbit(i)){         ret+=C[i];     }     ; ;     );     …