Hdu 2475-Box LCT,动态树】的更多相关文章

Box Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) [Problem Description] There are N boxes on the ground, which are labeled by numbers from 1 to N. The boxes are magical, the size of each one can be enlarged or r…
版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 2475 Splay树是一种神奇的东西... 题意: 有一些箱子,要么放在地上,要么放在某个箱子里面 . 现在有两种操作: (1) MOVE x y: 把 x 号箱子放到 y 号箱子里面,操作不合法就忽略这一次操作 . (2) QUERY x :  查询 x 号箱子最外面的箱子是哪一个 解法: 首先对所有的树进行一遍DFS,得到一个DFS序,可以把它看成是一个括号序列,开始访问某个节点是左括号,结束访问时是右括号 .这样这题就转换成用…
洛谷:P3690 [模板]Link Cut Tree (动态树) /*诸多细节,不注意就会调死去! 见注释.*/ #include<cstdio> #include<iostream> #include<algorithm> using namespace std; ; int n,m; ]; ]!=x && ch[fa[x]][]!=x; } ]]^xr[ch[x][]]^val[x]; } ]==x ;} ]]^=; rev[ch[x][]]^=;…
题面 题解 因为每个点都只能向后跳到一个唯一的点,但可能不止一个点能跳到后面的某个相同的点, 所以我们把它抽象成一个森林.(思考:为什么是森林而不是树?) 子节点可以跳到父节点,根节点再跳就跳飞了. 由于我们发现有一些父子关系要变,所以不能用树链剖分等静态的数据结构,可以用LCT(Link-Cut-Tree 联-切-树,即动态树,支持动态修改父子关系). 但是当我们询问答案的时候,我们发现wa了,那是因为我们询问的是x点到根的路径上的点数,但是各种LCT操作已经把原先的根不知换到那里去了,所以整…
题目:http://acm.fzu.edu.cn/problem.php?pid=2082 Problem 2082 过路费 Accept: 528    Submit: 1654Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description 有n座城市,由n-1条路相连通,使得任意两座城市之间可达.每条路有过路费,要交过路费才能通过.每条路的过路费经常会更新,现问你,当前情况下,从城市a到城市b最少要花多少过路费.  …
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3966 Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7658    Accepted Submission(s): 2024 Problem Description Our protagonist is the…
Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node is associated with an integer as the weight. Your task is to deal with M operations of 4 types: 1.Delete an edge (x, y) from the tree, and then add a…
Query on The Trees Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 4091    Accepted Submission(s): 1774 Problem Description We have met so many problems on the tree, so today we will have a que…
Box Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2813    Accepted Submission(s): 821 Problem Description There are N boxes on the ground, which are labeled by numbers from 1 to N. The boxes…
树型转线型.第一次听说这个概念. . . , 可是曾经已经接触过了,如LCA的预处理部分和树链剖分等.可是没想到还能这么用,三者虽说有不同可是大体思想还是非常相近的,学习了. 推荐博客http://blog.csdn.net/lyhypacm/article/details/6734748 转成线型之后.就变成了伸展树的模板题. 另外要注意,伸展树的特点是平均时间复杂度接近log(n).所以一定要记得每次操作之后都要伸展.再次学习了. #include <algorithm> #include…