8989: Fundamental Skills in Data Structures

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述


“To strengthen the fundamental skills in data structures and gain a profound understanding of the essence of data structures, as well as to implement code effectively, we need to make efforts to study the profound connotation of data structures...”

The ACM Training base is having a meeting, but after listening to only two sentences, Capoo the cat falls asleep. When he wakes up, he feels at a loss facing the homework left behind. Luckily, he knows a data structure expert, which is you! In order to prevent poor Capoo from being scolded by his senior, you decide to help him complete his data structure homework.

[capoo_confused.jpg](Please imagine it, we can't display it for you due to copyright reasons. T.T)

The homework questions are as follows:

Given a tree rooted at node 111, each node in the tree has a node weight ai∈{0,1}a_i\in \{0,1\}ai{0,1}. Now, you need to perform qqq operations, which can be divided into two types:
  •  111 uuu vvv xxx, which means setting the node weights of all the nodes on the simple path between uuu and vvv (inclusive) to xxx.
  •  222 uuu, which means querying the number of pairs of nodes (x,y)(x,y)(x,y) in the subtree rooted at uuu such that x<yx < yx<y and ax⊕ay⊕alca(x,y)=0a_x \oplus a_y \oplus a_{lca(x, y)}=0axayalca(x,y)=0 holds.

Here, ⊕\oplus represents the bitwise XOR operation, similar to the XOR operator (^) in C/C++.

lca(x,y)lca(x,y)lca(x,y) refers to the lowest common ancestor of nodes xxx and yyy. For example, in Sample 3, lca(4,5)=3lca(4,5)=3lca(4,5)=3.

输入格式


The first line consists of two integers, nnn and qqq (2≤n≤3×105,1≤q≤3×105)(2\leq n \leq 3\times 10^5,1\leq q\leq 3\times 10^5)(2n3×105,1q3×105), representing the number of nodes in the tree and the number of operations, respectively.
The second line contains nnn integers, aia_iai (ai∈{0,1})(a_i\in\{0,1\})(ai{0,1}), representing the initial node weights.
The third line contains n−1n-1n1 integers, where the iiith integer, fif_ifi (1≤fi≤i)(1\leq f_i\leq i)(1fii), represents the existence of an edge between the (i+1)(i+1)(i+1)th node and the fif_ifith node.
Following are qqq lines, each representing an operation:
For each operation, the first integer of the line, opopop (op∈{1,2})(op \in\{1,2\})(op{1,2}), denotes the type of operation.
  • If op=1op=1op=1, then the next three integers, uuu, vvv, and xxx (1≤u,v≤n,x∈{0,1})(1\leq u,v\leq n,x\in \{0,1\})(1u,vn,x{0,1}), represent the two endpoints of the covered chain and the assigned weight for that chain.
  • If op=2op=2op=2, then the next integer, uuu (1≤u≤n)(1\leq u\leq n)(1un), represents the root node of the subtree for which a query is required.

输出格式


For each query, output a single line containing an integer representing the answer to that query.

示例1

输入

复制 2 1 0 0 1 2 1
2 1
0 0
1
2 1

输出

复制 1
1
示例2

输入

复制 3 3 0 0 1 1 1 2 1 1 1 2 1 2 1
3 3
0 0 1
1 1
2 1
1 1 2 1
2 1

输出

复制 1 0
1
0
示例3

输入

复制 5 5 1 0 0 1 1 1 1 3 3 1 5 4 1 1 2 4 0 2 3 1 2 1 1 2 1
5 5
1 0 0 1 1
1 1 3 3
1 5 4 1
1 2 4 0
2 3
1 2 1 1
2 1

输出

复制 1 5
1
5

输入样例 复制

2 1
0 0
1
2 1

输出样例 复制

1

数据范围与提示


For Sample 3, in the first query, after the first two coverings, the node weights of the tree become {0,0,0,0,1}\{0,0,0,0,1\}{0,0,0,0,1}, and the valid point pairs in subtree 3 are (3,4)(3,4)(3,4).
In the second query, after the first three coverings, the node weights of the tree become {1,1,0,0,1}\{1,1,0,0,1\}{1,1,0,0,1}, and the valid point pairs in subtree 1 are (1,3),(1,4),(2,3),(2,4),(3,4)(1,3),(1,4),(2,3),(2,4),(3,4)(1,3),(1,4),(2,3),(2,4),(3,4).

分类标签