题面: Count on a tree 题解: 主席树维护每个节点到根节点的权值出现次数,大体和主席树典型做法差不多,对于询问(X,Y),答案要计算ans(X)+ans(Y)-ans(LCA(X,Y))-ans(father[LCA(X,Y)]) 代码: #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; +,maxm=m…
Count on a tree 题目描述 给定一棵\(N\)个节点的树,每个点有一个权值,对于\(M\)个询问\((u,v,k)\),你需要回答\(u\) \(xor\) \(lastans\)和\(v\)这两个节点间第\(K\)小的点权.其中\(lastans\)是上一个询问的答案,初始为\(0\),即第一个询问的u是明文. 输入输出格式 输入格式: 第一行两个整数\(N,M\). 第二行有\(N\)个整数,其中第\(i\)个整数表示点\(i\)的权值. 后面\(N-1\)行每行两个整数\((…
COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u …
[BZOJ2589][SPOJ10707]Count on a tree II 题面 bzoj 题解 这题如果不强制在线就是一个很\(sb\)的莫队了,但是它强制在线啊\(qaq\) 所以我们就用到了另一个东西:树分块 具体是怎么分块的呢:根据深度,从最深的叶子节点往上分,同一子树内的节点在一个块 比如说上面那张图, 有\(7\)个点,那么我们每隔\(2\)的深度就分一块 但是我们又要保证同一子树内的在一块,且要从最深的叶子节点一直往下 所以最后分块的结果:\((1,2)(7,6,3)(4,5)…
COT - Count on a tree #tree You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path from node u …
10628. Count on a tree Problem code: COT You are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight. We will ask you to perform the following operation: u v k : ask for the kth minimum weight on the path…