Under construction

Still being built. Things may change

Tree Colors and Queries 2

Time limit2sMemory limit256 MB

Summary
Given a rooted tree with colored vertices, cut parent edges online and count the distinct colors among the vertices still connected to each queried vertex.
Level

Hard8 of 10

Topics
Tree, Union-find, Segment tree
Solved
No attempts yet

Problem

A tree with NN vertices is given. The vertices are numbered 1 to NN, and each vertex has a color, which is a natural number from 1 to 100,000. Vertex 1 is the root. Since the graph is a tree, there is exactly one path between any two distinct vertices.

If a path between uu and vv exists, you can go from uu to vv.

You must process two kinds of queries.

  • 1 a: Remove the edge connecting vertex aa and its parent. This query is only given when that edge exists.
  • 2 a: Looking only at the vertices you can reach from vertex aa, print the number of distinct colors.

Input

The first line contains NN (1≤N≤100,0001 \le N \le 100{,}000) and QQ (1≤Q≤1,000,0001 \le Q \le 1{,}000{,}000), the number of vertices and the number of type 2 queries. The second line has N−1N-1 integers. The ii-th integer is the parent of vertex i+1i+1. The third line has NN integers. The ii-th integer is the color of vertex ii. The next N+Q−1N+Q-1 lines contain the queries: N−1N-1 of type 1 and QQ of type 2. Each query is a line with its type XX (1≤X≤21 \le X \le 2) and a non-negative integer kk. The vertex aa to process is k⊕lstk \oplus \mathrm{lst}, and 1≤a≤N1 \le a \le N. ⊕\oplus is bitwise XOR. lst\mathrm{lst} is the result of the most recent type 2 query, and its initial value is 0.

Output

For each of the QQ type 2 queries, print the answer on its own line, in order.

Examples1

  1. Example 1

    Input
    5 4
    5 2 2 1
    1 3 2 3 3
    1 4
    2 1
    2 0
    1 1
    2 6
    1 7
    2 1
    1 1
    
    Expected output
    3
    3
    2
    2