QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#15392. 神木辉

الإحصائيات

给定 $n$ 个顶点的树,顶点编号为 $1,\dots,n$,给定长度 $n_0$ 的序列 $a_1,\dots,a_{n_0}$,共 $m$ 次查询,每次查询给定 $l,r,x$,问树的顶点 $x$,依次向 $a_l,\dots,a_r$ 移动一步,到达的顶点。

若 $x=y$,则从顶点 $x$ 向 $y$ 移动一步到达 $x$,否则到达与 $x$ 在树上相邻且距离 $y$ 最近的位置。

输入格式

第一行三个整数 $n,n_0,m$;

接下来一行 $n-1$ 个整数依次表示 $f_2,\dots,f_n$,其中 $f_i$ 是顶点 $i$ 的父亲,$1$ 为根;

接下来一行 $n_0$ 个整数,依次表示 $a_1,\dots,a_{n_0}$;

接下来 $m$ 行,每行三个整数 $l\oplus v,r\oplus v,x\oplus v$ 表示一次查询,其中 $v$ 是上次查询的答案(特别地,第一次查询时 $v=0$),$\oplus$ 是按位异或。

输出格式

共 $m$ 行,依次为每次查询的答案。

样例数据

样例 1 输入

5 4 3
1 1 3 3
5 2 2 3
3 4 5
2 0 7
3 0 3

样例 1 输出

3
2
1

子任务

Idea:Ynoi,Solution:ccz181078,Code:ccz181078,Data:ccz181078

对 $100\%$ 的数据,满足 $1\le n,n_0,m\le 10^5$;

对于 $25\%$ 的数据,满足 $n,n_0,m\le 10^3$。

对于 $25\%$ 的数据,满足 $f_i=i-1$

对于 $25\%$ 的数据,满足 $f_i$ 在 $1,2,\dots,i-1$ 中均匀随机选取。

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.