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 操作。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.