主席树放到树上而已 #include <algorithm> #include <iostream> #include <cstdio> using namespace std; int n, m, lstans, uu, vv, a[100005], b[100005], rnk[100005], rem, cnt; int lson[2200005], rson[2200005], sum[2200005], rot[100005], qwq, ww; int fa…
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…
Count on a tree Time Limit:129MS Memory Limit:1572864KB 64bit IO Format:%lld & %llu Submit Status Practice SPOJ COT Description 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…
题面: 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…
SPOJ10707 COT2 Count on a tree II Solution 我会强制在线版本! Solution戳这里 代码实现 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #include<algorithm> #include<queue> #include<set> #include<map>…
BZOJ2589 Spoj 10707 Count on a tree II Solution 吐槽:这道题目简直...丧心病狂 如果没有强制在线不就是树上莫队入门题? 如果加了强制在线怎么做? 考虑分块(莫队与分块真是基友) 我们按照深度为\(\sqrt{n}\)的子树分块,那么这一棵树最多不超过\(\sqrt{n}\)个块. 维护每一个块的根节点到树上每一个节点的答案,暴力即可.然后用可持久化块状数组维护一下遍历时出现的最深的颜色的深度. 查询答案的做法: 在一个块内,直接暴力查. 不在一个…
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…
[BZOJ2588]Spoj 10628. Count on a tree Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个询问的u是明文. Input 第一行两个整数N,M. 第二行有N个整数,其中第i个整数表示点i的权值. 后面N-1行每行两个整数(x,y),表示点x到点y有一条边. 最后M行每行两个整数(u,v,k),表示一组…
一.题目 COT - Count on a 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)…
https://cn.vjudge.net/problem/SPOJ-COT 插上 大佬的代码 和 我的...以后再看吧... Count on a tree 大佬:http://www.cnblogs.com/Sunnie69/p/5511684.html #include <cstdio> #include <algorithm> #include <vector> using namespace std; +; int n,m,cnt,num; int a[max…
地址:http://www.spoj.com/problems/COT/en/ 题目: 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…
Count on a tree 题目描述 给定一棵\(N\)个节点的树,每个点有一个权值,对于\(M\)个询问\((u,v,k)\),你需要回答\(u\) \(xor\) \(lastans\)和\(v\)这两个节点间第\(K\)小的点权.其中\(lastans\)是上一个询问的答案,初始为\(0\),即第一个询问的u是明文. 输入输出格式 输入格式: 第一行两个整数\(N,M\). 第二行有\(N\)个整数,其中第\(i\)个整数表示点\(i\)的权值. 后面\(N-1\)行每行两个整数\((…
COT2 - Count on a tree II http://www.spoj.com/problems/COT2/ #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 : ask for how many…