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$ 中均匀随机选取。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.