QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#7455. stcm

Statistics

给定一棵树,你可以维护一个集合,支持三种操作:

  1. 当前集合中插入一个节点 $x$
  2. 撤回上一次插入操作
  3. 将当前点集标为第 $i$ 个点的子树补信息

一个点 $x$ 的子树补信息定义为,树的点集除去 $x$ 的子树(包括 $x$)内的点得到的集合; 需要保证每个点的子树补信息都是正确的。

输入格式

本题输入含有多组测试数据。

一组测试数据格式为:

第一行一个正整数 $n$。

之后一行 $n-1$ 个正整数,第 $i$ 个数表示 $i+1$ 节点的父亲节点 $j$,保证 $j < i+1$。

请读入至 EOF。

输出格式

对每一组数据,输出一个字符串,从左往右,每个"+x"形式的子串代表进行一次 1 操作,对象为编号 $x$ 的节点,每个"-"子串代表进行一次 2 操作,每个"=x"形式的子串代表进行一次 3 操作,对象为编号 $x$ 的节点,每个"!"子串代表全部操作都已结束,在其后面的任何输入会被忽略,字符串必须以"!"表示结束。

输出的字符串中不允许以任何空白字符分隔。

样例数据

样例输入

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

样例输出

=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!

子任务

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

对于 $100\%$ 的数据,满足 $1\le n\le 10^5$,$1\le T\le 3$。

允许进行的 1 操作次数为 $4.5 \times 10^6$ 次,不允许插入一个当前集合中存在的元素。

当最后一次未被撤回的插入操作不存在时,不允许进行 2 操作。

对每个点,必须对其进行恰好一次 3 操作。

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.