lca的做法还是非常明显的.简单粗暴, 只是不是正解.假设树是长链就会跪,直接变成O(n).. 最后跑的也挺快,出题人还是挺阳光的.. 动态树的解法也是听别人说能ac的.预计就是放在splay上剖分一下,做法还是比較复杂的.,, 来一发lca: #include <stdio.h> #include <iostream> #include <algorithm> #include <sstream> #include <stdlib.h> #in…
The Query on the Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 57    Accepted Submission(s): 20 Problem Description 度度熊近期沉迷在和树有关的游戏了.他一直觉得树是最奇妙的数据结构. 一天他遇到这样一个问题: 有一棵树,树的每一个点有点权,每次有三种操作:…
https://www.luogu.org/problemnew/show/P3379 1.欧拉序+rmq(st) /* 在这里,对于一个数,选择最左边的 选择任意一个都可以,[left_index,right_index],深度都大于等于这个数的深度 */ #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <time.h> #inc…
一看就是欧拉降幂,问题是怎么求$fib(a^b)$,C给的那么小显然还是要找循环节.数据范围出的很那啥..unsigned long long注意用防爆的乘法 /** @Date : 2017-09-25 15:17:05 * @FileName: HDU 2814 斐波那契循环节 欧拉降幂.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https://github.com/ * @Ve…
什么是欧拉序,可以去这个大佬的博客(https://www.cnblogs.com/stxy-ferryman/p/7741970.html)巨详细 因为欧拉序中的两点之间,就是两点遍历的过程,所以只要找遍历过程中对应的最小的深度就行了,这里用st表存,first存第一个u出现的地方,用value存欧拉序,同时用depth存对应深度 模板 struct node{ int v,next,dist; }a[maxn<<]; int n,m,tot,len; ][], depth[maxn<…
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=4676 Sum Of Gcd Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 908    Accepted Submission(s): 438 Problem Description Given you a sequence of numb…
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…
题目 给出一棵有n个结点的树,树根是1,每个结点给出一个value.然后给出q个询问,每个询问给出两个整数u和x,你要在以u结点为根的子树中找出一个结点v,使得val[v] xor x最大, 并输出这个最大值 分析 显而易见的可持久化字典树,只不过这次每次查询不是查询一个区间,而是查询一棵子树.那么也很简单,我们只要预处理出dfs序然后找出每个结点以它为根的子树在dfs序中的区间.然后以这个区间建可持久化字典树就可以了. #include <cstdio> #include <cstri…
题目链接 题意:给出一些单词,问全部单词能否首尾相连 直接 将每一个单词第一个和最后一个字母建立一条有向边,保证除了首尾两个出入度不相等,其他的要保证相等.还有一个条件就是 首尾两个出入度差为1 同时并查集判连通 #include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; +…
找新朋友 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7001    Accepted Submission(s): 3643 Problem Description 新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数…