10pts
查看原帖
10pts
365641
SKP_677楼主2020/11/6 21:49
#include<iostream>
#include<cstdio>
using namespace std;
struct node{
	int cntl,cntr,cnt;
}tree[500005];
char c[500005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>c[i];
	if(c[1]=='(')
		tree[1].cntl++;
	int f;
	for(int i=2;i<=n;i++)
		{
			cin>>f;
			if(c[i]=='(')
			{
				tree[i].cntl=tree[f].cntl+1;
				tree[i].cnt=tree[f].cnt;
			}
			else
			{
				if(tree[f].cntl){
					tree[i].cnt=tree[f].cnt+1;
					tree[i].cntl=tree[f].cntl-1;
				}
				else tree[i].cnt=tree[f].cnt;
			}
		}
	int sum=0;
	for(int i=1;i<=n;i++)
	
	sum=sum^(i*tree[i].cnt);
	cout<<sum;	
	return 0;
}
2020/11/6 21:49
加载中...