Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16180   Accepted: 4836 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…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18623   Accepted: 5629 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…
题目链接:http://poj.org/problem?id=3321 Apple Tree Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34812 Accepted: 10469 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka like…
题意: 一棵苹果树有N个分叉,编号1---N(根的编号为1),每个分叉只能有一颗苹果或者没有苹果. 现在有两种操作: 1.某个分叉上的苹果从有变无或者从无边有. 2.需要统计以某个分叉为根节点时,它的子树上(包括该分叉)共有多少苹果. 分析: 有两种操作,基本就是使用数据结构维护的题目了.开始想了很久,不懂如何将分叉转化为一维线性的树状数组维护. 看了下discuss,有人说了时间戳三字.想了想,发现如果按照节点遍历的顺序可以制造出时间上的线性关系. 例如: 连接情况为:1---->2    …
题目:http://poj.org/problem?id=3321 题意: 苹果树上n个分叉,Q是询问,C是改变状态.... 开始的处理比较难,参考了一下大神的思路,构图成邻接表 并 用DFS编号 白书上一维树状数组模板: int lowbit(int x) { return x&(-x); } void add(int x,int d) //c[]的下标要从 1开始. { while(x <= n) { c[x] += d; x +=lowbit(x); } } int sum(int x…
点我看题目  题意 : 大概是说一颗树有n个分岔,然后给你n-1对关系,标明分岔u和分岔v是有边连着的,然后给你两个指令,让你在Q出现的时候按照要求输出. 思路 :典型的树状数组.但是因为没有弄好数组,所以要用DFS先映射一下,好吧我承认我说不下去了,六级没过,CF又掉了100多分,脑子完全不转转了...... #include <iostream> #include <stdio.h> #include <string.h> using namespace std;…
树上的单点修改+子树查询 用dfn[u]和num[u]可以把任意子树表示成一段连续区间,此时结合树状数组就好了 #include <set> #include <map> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <…
模板: int n; int tree[LEN]; int lowbit(int x){ return x&-x; } void update(int i,int d){//index,delta while(i<=n){ tree[i]+=d; i+=lowbit(i); } } int getsum(int i){ ; ){ ans+=tree[i]; i-=lowbit(i); } return ans; } 示意图: 1.Ultra-QuickSort 大佬代码: //树状数组 #i…
题意:给2个数字序列 a 和 b ,问按从小到达排序后,a中的哪些子串与b的名次匹配. a 的长度 N≤100,000,b的长度 M≤25,000,数字的大小 K≤25. 解法:[思考]1.X 暴力.枚举 a 中的子串,选出来排序后比对名次.O(n*  m log m  *m)=O(n*m^2*log m).    2.X  暴力+树状数组优化.枚举 a 中的子串,选出来后比较前缀名次(P.S.这种转化常出现,比如:[洛谷 p3368]模板-树状数组 2(数据结构) 就是将个体转化为前缀.),看…