poj3321Apple Tree(树状数组)】的更多相关文章

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];     }     ; ;     );     …
由于智力的问题,百度之星完全lu不动..开场看第一题根据题目给的条件我觉得一定是可以构造出来的,题目给的意思颇有鸽巢原理的感觉,于是觉得开场第一题应该就是智力构造题了,想了半个小时,发现完全想不动,于是只能放弃了去想后面的题. 然后看第二题的数据结构,树上的询问,支持点修改,询问子树和,还有换根,然后心里想,我擦,这不是LCT么,但是我没学呀,然后细心的翻出之前打印的论文研读了很久,发现普通的LCT只能解决询问树路径上的东西,然后看论文上写如果支持子树操作的话就需要Euler-tour-tree…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3333 题意就是询问区间不同数字的和. 比较经典的树状数组应用. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #inc…