ICM Technex 2018 and Codeforces Round 463 (Div. 1 + Div. 2, combined)
D
Tree
Codeforces
2200
原题
← CE →
翻译中…

You are given a node of the tree with index $1$ and with weight $0$. Let $*cnt*$ be the number of nodes in the tree at any instant (initially, $*cnt*$ is set to $1$). Support $*Q*$ queries of following two types:

翻译中…
  • image Add a new node (index $*cnt* + 1$) with weight $*W*$ and add edge between node $*R*$ and this node.
  • image Output the maximum length of sequence of nodes which
  • starts with $*R*$.
    • Every node in the sequence is an ancestor of its predecessor.
    • Sum of weight of nodes in sequence does not exceed $*X*$.
    • For some nodes $*i*, *j*$ that are consecutive in the sequence if $*i*$ is an ancestor of $*j*$ then $*w*[*i*] ≥ *w*[*j*]$ and there should not exist a node $*k*$ on simple path from $*i*$ to $*j*$ such that $*w*[*k*] ≥ *w*[*j*]$
翻译中…

The tree is rooted at node $1$ at any instant.

翻译中…

Note that the queries are given in a modified way.

翻译中…

Input

翻译中…

First line containing the number of queries $*Q*$ $(1 ≤ *Q* ≤ 400000)$.

翻译中…

Let $*last*$ be the answer for previous query of type $2$ (initially $*last*$ equals $0$).

翻译中…

Each of the next $*Q*$ lines contains a query of following form:

翻译中…
  • 1 p q ($1 ≤ *p*, *q* ≤ 10^{18}$): This is query of first type where image and image. It is guaranteed that $1 ≤ *R* ≤ *cnt*$ and $0 ≤ *W* ≤ 10^{9}$.
  • 2 p q ($1 ≤ *p*, *q* ≤ 10^{18}$): This is query of second type where image and image. It is guaranteed that $1 ≤ *R* ≤ *cnt*$ and $0 ≤ *X* ≤ 10^{15}$.
翻译中…

image denotes bitwise XOR of $*a*$ and $*b*$.

翻译中…

It is guaranteed that at least one query of type 2 exists.

翻译中…

Output

翻译中…

Output the answer to each query of second type in separate line.

翻译中…

Note

翻译中…

In the first example,

翻译中…

$*last* = 0$

翻译中…
  • Query 1: 1 1 1, Node $2$ with weight $1$ is added to node $1$.
翻译中…
  • Query 2: 2 2 0, No sequence of nodes starting at $2$ has weight less than or equal to $0$. $*last* = 0$
翻译中…
  • Query 3: 2 2 1, Answer is $1$ as sequence will be ${2}$. $*last* = 1$
翻译中…
  • Query 4: 1 2 1, Node $3$ with weight $1$ is added to node $2$.
翻译中…
  • Query 5: 2 3 1, Answer is $1$ as sequence will be ${3}$. Node $2$ cannot be added as sum of weights cannot be greater than $1$. $*last* = 1$
翻译中…
  • Query 6: 2 3 3, Answer is $2$ as sequence will be ${3, 2}$. $*last* = 2$
翻译中…

样例

Input #1
6
1 1 1
2 2 0
2 2 1
1 3 0
2 2 0
2 2 2
Output #1
0
1
1
2
InputCopy OutputCopy
Input #2
6
1 1 0
2 2 0
2 0 3
1 0 2
2 1 3
2 1 6
Output #2
2
2
3
2
InputCopy OutputCopy
Input #3
7
1 1 2
1 2 3
2 3 3
1 0 0
1 5 1
2 5 0
2 4 0
Output #3
1
1
2
InputCopy OutputCopy
Input #4
7
1 1 3
1 2 3
2 3 4
1 2 0
1 5 3
2 5 5
2 7 22
Output #4
1
2
3
InputCopy OutputCopy
题目信息
题号
932D
时间限制
2 s
内存限制
512 MB
标签
二分
动态规划
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。