QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875196#9641. Two permutationsucup-team0520 1ms14372kbC++231.9kb2025-01-29 12:37:002025-01-29 12:37:01

Judging History

This is the latest submission verdict.

  • [2025-01-29 12:37:01]
  • Judged
  • Verdict: 0
  • Time: 1ms
  • Memory: 14372kb
  • [2025-01-29 12:37:00]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
#define N 400005
int pre[N],suf[N],v[N],a[N],pos[N],op[N],op2[N],n;
void work()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		v[i]=read();
		if(v[i]>i)
		{
			cout<<"No\n";
			return ;
		}
	}
	memset(pre,0,sizeof(pre));
	memset(suf,0,sizeof(suf));
	int H=0,T=2*n+1;
	suf[H]=T,pre[T]=H;
	auto ins=[&](int pos,int val) // pos (val) pos+1
	{
		int nxt=suf[pos];
		suf[pos]=val,pre[val]=pos;
		suf[val]=nxt,pre[nxt]=val;
	};
	auto print=[&]()
	{
		int cur=H;
		for(int i=1;i<=2*n;i++)
		{
			cur=suf[cur];
			if(cur==T) break;
			if(cur<=n) a[i]=cur;
			else a[i]=cur-n;
		}
		for(int i=1;i<=n*2;i++) printf("%d%c",a[i]," \n"[i==n*2]);
	};
	int mid=H;
	for(int i=1;i<=n;i++)
	{
		if(v[i]==i) 
		{
			ins(mid,i+n);
			ins(H,i);
			pos[i]=i;
			op[i]=0,op2[i]=1;
			if(i==1) mid=i;
		}
		else
		{
			int p=pos[v[i]],o=op[p],o2=op2[p];
			if(o2==0)
			{
				if(o==0)
				{
					ins(pre[p],i+n),ins(pre[T],i);
					pos[i]=i,op[i]=1,op2[i]=1;
				}
				else
				{
					ins(H,i),ins(p,i+n);
					pos[i]=i,op[i]=0,op2[i]=1;
				}
			}
			else
			{
				if(o==0)
				{
					ins(mid,i),ins(p,i+n); mid=pre[i];
					pos[i]=i,op[i]=1,op2[i]=0;
				}
				else
				{
					ins(pre[p],i+n),ins(mid,i); mid=i;
					pos[i]=i,op[i]=0,op2[i]=0;
				}
			}
		}
		print();
	}
	cout<<"Yes\n";
	print();
}
signed main()
{
	int T=read(); while(T--) work();
	return 0;
}



詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 14372kb

input:

10
1
1
2
1 1
3
1 2 2
4
1 1 3 2
5
1 2 1 2 1
2
1 1
1
1
3
1 2 2
1
1
5
1 1 1 3 2

output:

1 1
Yes
1 1
1 1 0 0
1 2 2 1
Yes
1 2 2 1
1 1 2 1 0 0
2 1 2 1 0 0
2 3 1 3 2 1
Yes
2 3 1 3 2 1
1 1 1 3 2 1 0 0
1 2 2 1 2 1 0 0
3 1 2 3 2 1 0 0
4 3 1 2 3 2 4 1
Yes
4 3 1 2 3 2 4 1
1 1 1 2 3 2 4 1 0 0
2 1 2 1 3 2 4 1 0 0
2 1 3 3 2 1 4 1 0 0
2 4 1 3 4 3 2 1 0 0
2 4 1 5 3 5 4 3 2 1
Yes
2 4 1 5 3 5 4 3 2 1
...

result:

wrong answer Wrong Answer![1]

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 13612kb

input:

10
10
1 2 3 4 3 1 2 4 3 8
10
1 2 1 1 4 6 4 5 2 9
10
1 2 2 4 5 3 7 7 2 3
10
1 1 2 4 5 4 3 5 7 7
10
1 2 2 4 4 1 6 6 6 10
10
1 2 2 4 1 3 7 7 1 10
10
1 2 3 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

10
199850
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #19:

score: 0
Time Limit Exceeded

input:

10
199755
1 2 1 3 5 1 6 7 2 1 5 6 10 9 12 2 4 14 2 18 5 17 23 4 6 7 4 6 20 27 16 24 29 8 33 26 33 27 17 39 5 33 34 41 4 16 24 19 42 8 29 48 48 27 37 24 43 13 4 28 38 27 38 23 29 55 14 62 26 9 62 20 35 31 57 74 69 5 26 60 33 59 5 19 21 45 15 87 3 54 17 2 57 36 18 67 25 62 47 53 89 27 5 59 75 77 29 9 ...

output:

1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result: