AT. 【模板】树上 K 级祖先
【模板】树上 K 级祖先
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
题目背景
本题仅作为长链剖分求树上 级祖先评测用,不保证卡掉了其他复杂度不正确的做法。
题目描述
给定一棵 个点的有根树。
有 次询问,第 次询问给定 ,要求点 的 级祖先,答案为 。特别地,。
本题中的询问将在程序内生成。
给定一个随机种子 和一个随机函数 :
#define ui unsigned int
ui s;
inline ui get(ui x) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return s = x;
}
你需要按顺序依次生成询问。
设 为点 的深度,其中根的深度为 。
对于第 次询问,$x_i = ((\operatorname{get}(s) \operatorname{xor} ans_{i-1}) \bmod n) + 1$,$k_i = (\operatorname{get}(s) \operatorname{xor} ans_{i-1}) \bmod d_{x_i}$。
输入格式
第一行三个整数 。
第二行 个整数 ,其中 表示 的父亲。特别地,若 ,则 为根。
输出格式
一行一个整数,表示 。
6 3 7
5 5 2 2 0 3
1
提示
【样例说明】
,,;
,,;
,,;
故输出 。
对于 的数据,。
对于 的数据,。
对于 的数据,,,。
【蒙青创】A班CSP备战模板
- Status
- Done
- Problem
- 68
- Open Since
- 2025-10-24 0:00
- Deadline
- 2025-10-31 23:59
- Extension
- 24 hour(s)