QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 1024 MB Total points: 100

#8950. 树据结构

Statistics

$n$ 個の頂点からなる木が与えられる。この木は以下の性質を満たす。

  1. すべての葉の深さは等しい。
  2. 頂点には BFS 順で番号が付けられている。構築方法は以下の通りである。
    1. 根を頂点 1 とし、キューに 1 を入れる。
    2. キューから頂点を取り出し、その子に未使用の番号を順に割り当て、番号順にキューに入れる。

各頂点には重みが設定されており、初期値はすべて 0 である。

以下の 2 種類の操作が与えられる。

  • 操作 1:頂点 $x$ を根とする部分木に含まれるすべての頂点の重みに $y$ を加算する。
  • 操作 2:頂点の重みを巡回させる。頂点 $i$ の重みを頂点 $(i \bmod n) + 1$ に移動させる。

$q$ 回の操作後の各頂点の重みを求めよ。出力が大きくなることを避けるため、すべての頂点の重みの排他的論理和(XOR)を出力せよ。

制約

すべてのデータにおいて、$n, Q \leq 100\,000$、$y \leq 10\,000$ を満たす。

小課題 $n, Q \leq$ 特殊性質 配点
1 $1\,000$ なし 21
2 $100\,000$ 操作 1 のみ 8
3 $100\,000$ $fa[i+1]=i$ 8
4 $100\,000$ 完全二分木である ($n=2^k-1$) 13
5 $100\,000$ 葉の数 $\leq 20$ 13
6 $50\,000$ なし 21
7 $100\,000$ なし 16

入力形式

入力は以下の形式で標準入力から与えられる。

$n$ $q$ $fa[2]$ $fa[3]$ $\dots$ $fa[n]$ 操作 1 $\vdots$ 操作 $q$

$fa[i+1]$ は頂点 $i+1$ の親を表す(BFS の性質により、$i \leq j$ ならば $fa[i] \leq fa[j]$ が成り立つ)。 各操作は以下のいずれかの形式である。

1 x y:操作 1 を行う。 2:操作 2 を行う。

出力形式

すべての頂点の重みの排他的論理和を 1 行で出力せよ。

入出力例

入力 1

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

出力 1

10

注記

最終的な各頂点の重みは以下の通りである。

9 11 6 6 5 13

これらの排他的論理和は 10 となる。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.