SP1487 PT07J - Query on a tree III

题目描述

你被给定一棵带点权的 $n$ 个点的有根树,点从 $1$ 到 $n$ 编号。 定义查询 $q(x,k)$:寻找以 $x$ 为根的子树中的第 $k$ 小点的编号(从小到大排序第 $k$ 个点)。 保证没有两个相同的点权。

输入格式

The first line contains one integer _n_ (1

输出格式

For each query (_x_, _k_), output the index of the node whose label is the _k_-th largest in the subtree of the node _x_.