[ SPOJ PT07J ] Query on a tree III】的更多相关文章

PT07J - Query on a tree III #tree You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels. Input The first line c…
\(\\\) Description 其实这题才是正版的 Qtree3...... 给定 \(n\) 个点,以 \(1\) 号节点为根的树,点有点权. \(m\) 次询问 以 \(x\) 为根的子树内,点权第 \(k\) 小的 节点编号 是多少. 有多组测试数据,每组数据以 \(DONE\) 结尾. \(n,m\le 10^5\) \(\\\) Solution 注意到一棵树的子树 \(DFS\) 序是连续的. 一遍 \(DFS\) 确定 \(DFS\) 序以及各个点的子树大小. 在 \(DFS…
SP1487 PT07J - Query on a tree III 题意翻译 你被给定一棵带点权的n个点的有根数,点从1到n编号. 定义查询 query(x,k): 寻找以x为根的k大点的编号(从小到大排序第k个点) 假设没有两个相同的点权. 输入格式: 第一行为整数n,第二行为点权,接下来n-1行为树边,接下来一行为整数m,下面m行为两个整数x,k,代表query(x,k) 输出格式: m行,输出每次查询的结果. Translated by @vegacx 题目描述 You are give…
题目链接:http://www.spoj.com/problems/PT07J/ 题意:给出一个有根树,1为根节点,每个节点有权值.若干询问,询问以u为根的子树中权值第K小的节点编号. 思路:DFS一次,记录每个节点在DFS序列中的开始和结束位置.那么以u为节点的子树的所有点都在两个u之间.那么询问就转化成询问区间的第K小值,可以将DFS序列建立划分树解决. #include <iostream>#include <cstdio>#include <string.h>#…
Code: #include<iostream> #include<cstdio> #include<algorithm> #include<string> #include<cstring> #define REP(i,a,n)for(int i=a;i<=n;++i) #define CLR(d,a)memset(d,a,sizeof(d)); using namespace std; void SetIO(string a){ str…
[BZOJ1803]Spoj1487 Query on a tree III Description You are given a node-labeled rooted tree with n nodes. Define the query (x, k): Find the node whose label is k-th largest in the subtree of the node x. Assume no two nodes have the same labels. Input…
「SPOJ1487」Query on a tree III 传送门 把树的 \(\text{dfs}\) 序抠出来,子树的节点的编号位于一段连续区间,然后直接上建主席树区间第 \(k\) 大即可. 参考代码: #include <algorithm> #include <cstdio> #define rg register #define file(x) freopen(x".in", "r", stdin), freopen(x"…
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB   This problem will be judged on SPOJ. Original ID: QTREE64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Font Size: + - Type:   None Graph…
题目链接:http://www.spoj.com/problems/QTREE/en/ QTREE - Query on a tree #tree You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1. We will ask you to perfrom some instructions of the following form:…
Query on a tree again! 给出一棵树,树节点的颜色初始时为白色,有两种操作: 0.把节点x的颜色置反(黑变白,白变黑). 1.询问节点1到节点x的路径上第一个黑色节点的编号. 分析: 先树链剖分,线段树节点维护深度最浅的节点编号. 注意到,如果以节点1为树根时,显然每条重链在一个区间,并且区间的左端会出现在深度浅的地方.所以每次查找时发现左区间有的话,直接更新答案. 9929151 2013-08-28 10:45:55 Query on a tree again! 100…