A - Aragorn's Story HDU - 3966 树剖裸题】的更多相关文章

这个题目是一个比较裸的树剖题,很好写. http://acm.hdu.edu.cn/showproblem.php?pid=3966 #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include &…
HDU - 3966 思路 :树链剖分就是可以把一个路径上的点映射成几段连续的区间上.这样对于连续的区间可以用线段树维护, 对于每一段连续的区间都可以通过top [ ]数组很快的找到这段连续区间的头.跳的过程类似于 lca ,但这里 要注意的是 每一个点只属于一条链. (重载运算符时要注意   node 一个 新的结点,不要 乱用*this 指针) #include<bits/stdc++.h> using namespace std; #define MID int m = (l+r)/2…
#include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #define foru(i,x,y) for(int i=x;i<=y;i++) #define clr(a) memset(a,0,sizeof(a)) using namespace std; ; ]; *N]; int d[N],id[N],head[N],f[N],siz[N],son[N],top[N…
Problem Aragorn's Story (HDU 3966) 题目大意 给定一颗树,有点权. 要求支持两种操作,将一条路径上的所有点权值增加或减少ai,询问某点的权值. 解题分析 树链剖分模板题. 实质上树链剖分进行了点对点的一次映射,保证了重链上的点在线段树上的位置是连续的. 树链剖分的两个性质(转): 性质1:如果(v,u)为轻边,则siz[u] * 2 < siz[v]: 性质2:从根到某一点的路径上轻链.重链的个数都不大于logn. 保证了一个区间的时间复杂度是log2(n).…
Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10510    Accepted Submission(s): 2766 Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lor…
原题链接 对于以u为根的子树,后代节点的dfn显然比他的dfn大,我们可以记录一下回溯到u的dfn,显然这两个dfn构成了一个连续区间,代表u及u的子树 剩下的就和树剖一样了 #include<cstdio> #include<algorithm> #include<cstring> #define N 100010 typedef long long ll; using namespace std; int ecnt,head[N],son[N],fa[N],sz[N…
本来是打算作为树剖练习的最后一题的,结果一直WA. 本来以为是自己写的太丑. 最后发现5w的数据 我开了10w的数组 然而有一个数组要×2 哦,好棒棒. #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define foru(i,x,y) for(LL i=x;i<=y;i++) using namespace std; typedef int LL; co…
传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.csdn.net/zhhe0101/article/details/53871453  https://yq.aliyun.com/articles/252586 [2]树链剖分:http://blog.sina.com.cn/s/blog_7a1746820100wp67.html    https…
题意: http://acm.hdu.edu.cn/showproblem.php?pid=3966 给一棵树,并给定各个点权的值,然后有3种操作: I x y z : 把x到y的路径上的所有点权值加上z D x y z:把x到y的路径上的所有点权值减去z Q z:查询节点编号为x的权值 这里主要放下用树状数组维护的模板 区间修改单点查询 好像用线段树更好? em.... 两种都放好了~ 好像说hduoj是windows系统容易爆栈 手动扩栈加这句 #pragma comment(linker,…
思路:树链剖分入门题,我这门入得好苦啊,程序很快写出来了,可是在LCA过程中把update函数里的左右边界位置写反了,一直RE到死. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<set> #include<map> #include<cmath> #include<queue> #include<cstdio> #include<vec…