QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100

#7455. stcm

统计

Given a tree, you can maintain a set that supports three types of operations:

  1. Insert a node $x$ into the current set.
  2. Undo the last insertion operation.
  3. Mark the current set of nodes as the subtree complement information for the $i$-th node.

The subtree complement information of a node $x$ is defined as the set of nodes obtained by removing all nodes in the subtree of $x$ (including $x$ itself) from the set of all nodes in the tree. You must ensure that the subtree complement information for every node is correct.

Input

This problem contains multiple test cases.

Each test case is formatted as follows:

The first line contains a positive integer $n$.

The next line contains $n-1$ positive integers, where the $i$-th number represents the parent $j$ of node $i+1$. It is guaranteed that $j < i+1$.

Read until EOF.

Output

For each test case, output a string. From left to right, each substring in the form "+x" represents performing operation 1 on node $x$, each "-" substring represents performing operation 2, each "=x" substring represents performing operation 3 on node $x$, and each "!" substring represents that all operations are finished; any input following it will be ignored. The string must end with "!".

The output string must not contain any whitespace characters.

Examples

Input 1

6
1 1 2 3 3
6
1 1 2 3 3

Output 1

=1+1+3+5+6=2+2=4----+4+2=3+3+6=5-+5=6!
=1+1+3+5+6=2+2=4----+4+2=3+3+6=5-+5=6!

Subtasks

Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078 & nzhtl1477

For $100\%$ of the data, $1 \le n \le 10^5$ and $1 \le T \le 3$.

The number of allowed type 1 operations is $4.5 \times 10^6$. It is not allowed to insert an element that is already present in the current set.

When there is no last un-undone insertion operation, type 2 operations are not allowed.

For each node, you must perform exactly one type 3 operation.

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.