QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386955#7455. stcmKevin5307WA 87ms6916kbC++231.9kb2024-04-11 21:57:362024-04-11 21:57:38

Judging History

你现在查看的是最新测评结果

  • [2024-04-11 21:57:38]
  • 评测
  • 测评结果:WA
  • 用时:87ms
  • 内存:6916kb
  • [2024-04-11 21:57:36]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
vector<int> G[100100];
int dfn[100100],out[100100],val[100100],n,tot;
void dfs(int x)
{
	dfn[x]=++tot;
	val[tot]=x;
	for(auto y:G[x])
		dfs(y);
	out[x]=tot;
}
void solve(int l,int r,vector<array<int,3>> vq)
{
	if(!sz(vq)) return ;
	if(l==r)
	{
		for(auto arr:vq)
			cout<<"="<<arr[2];
		return ;
	}
	int mid=(l+r)/2;
	vector<array<int,3>> vl,vr,vmid;
	for(auto arr:vq)
		if(arr[1]<=mid)
			vl.pb(arr);
		else if(arr[0]>mid)
			vr.pb(arr);
		else
			vmid.pb(arr);
	for(int i=l;i<=mid;i++)
		cout<<"+"<<val[i];
	solve(mid+1,r,vr);
	for(int i=l;i<=mid;i++)
		cout<<"-";
	for(int i=mid+1;i<=r;i++)
		cout<<"+"<<val[i];
	solve(l,mid,vl);
	srt(vmid);
	int lp=l,rp=r;
	for(auto arr:vmid)
	{
		while(lp<arr[0])
			cout<<"+"<<val[lp++];
		while(rp>arr[1])
			cout<<"+"<<val[rp--];
		cout<<"="<<arr[2];
	}
	while(lp>l)
	{
		cout<<"-";
		lp--;
	}
	while(rp<r)
	{
		cout<<"-";
		rp++;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while(cin>>n)
	{
		tot=0;
		for(int i=1;i<=n;i++)
			G[i].clear();
		for(int i=2;i<=n;i++)
		{
			int f;
			cin>>f;
			G[f].pb(i);
		}
		dfs(1);
		vector<array<int,3>> vec;
		for(int i=1;i<=n;i++)
			vec.push_back({dfn[i],out[i],i});
		solve(1,n,vec);
		cout<<"!\n";
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 87ms
memory: 6916kb

input:

1000
1 1 2 1 1 2 2 7 2 7 3 11 10 6 4 8 10 13 16 2 19 7 6 18 6 2 16 27 21 14 6 14 14 29 12 13 3 27 28 27 2 34 26 27 44 14 30 25 7 50 47 1 36 24 4 32 10 20 53 52 61 23 43 39 2 15 47 9 14 54 48 53 36 14 14 66 76 55 17 67 21 22 18 25 67 75 7 48 21 6 35 11 31 41 63 28 6 98 51 3 29 52 102 77 27 58 39 64 9...

output:

+1+2+4+16+20+59+406+711+28+40+566+985+97+977+256+299+403+427+450+477+734+478+654+321+595+492+275+610+627+668+685+756+825+760+793+924+984+361+56+162+173+174+179+399+886+896+479+626+567+885+341+823+201+580+706+986+997+777+863+389+738+848+354+680+7+9+69+149+339+964+413+577+866+692+325+11+13+19+22+83+41...

result:

wrong answer -1 / -1 / -1