#P10990. [蓝桥杯 2023 国 Python A] 彩色二叉树

[蓝桥杯 2023 国 Python A] 彩色二叉树

Background

It is recommended to use PyPy3 to submit this problem.

Problem Description

Given a complete binary tree with nn nodes. The figure below shows a complete binary tree with n=6n = 6 nodes.

All nodes on the tree are initially uncolored, with color 00.

There are qq operations. Each operation can be:

  1. xi yi zix_i\ y_i\ z_i: set the color of all nodes whose distance to node xix_i is less than or equal to yiy_i to ziz_i.
  2. xix_i: query the color of node xix_i.

Input Format

The first line contains two integers n,qn, q, separated by a space.

In the next qq lines, each line contains one operation, and adjacent integers are separated by a space. It is guaranteed that every operation is valid.

Output Format

For each query operation, output one line containing one integer representing the corresponding answer.

6 6
1 1 1 1
2 3
1 5 2 2
2 4
2 1
2 3


1
2
2
1

Hint

For 40%40\% of the testdata, n,q5000n, q \le 5000.

For all testdata, 1n1061 \le n \le 10^6, 1q2×1051 \le q \le 2 \times 10^5, 1xin1 \le x_i \le n, 1yi1061 \le y_i \le 10^6, 1zi1061 \le z_i \le 10^6.

Translated by ChatGPT 5