UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201107#3482. sortableJosephcheng10067ms1752kbC++11847b2024-01-21 09:19:412024-01-21 12:03:26

answer

#include<bits/stdc++.h>
using namespace std;

int q,n,pos1,pos2,pos3;
int a[100005],stk[100005],que[100005];

void now()
{
	printf("\npos1=%d,pos2=%d,pos3=%d",pos1,pos2,pos3);
	printf("\nA:");
	for(int i=pos1+1;i<=n;i++)
		printf("%d ",a[i]);
	printf("\nS:");
	for(int i=1;i<=pos2;i++)
		printf("%d ",stk[i]);
	printf("\nB:");
	for(int i=1;i<=pos3;i++)
		printf("%d ",que[i]);
	puts("");
}

void solve()
{
	pos1=0,pos2=0,pos3=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	while(pos1<n||pos2>0){
		if((pos2==0||a[pos1+1]<stk[pos2])&&pos1<n) stk[++pos2]=a[++pos1];
		else que[++pos3]=stk[pos2--];
//		now();
	}
	for(int i=2;i<=pos3;i++){
		if(que[i]<que[i-1]){
			printf("NO\n");
			return;
		}
	}
	printf("YES\n");
	return ;
}

int main()
{
	scanf("%d",&q);
	while(q--)
		solve();
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

10
10
4 2 1 3 8 7 6 5 9 10
10
3 7 6 4 8 10 5 9 2 1
10
1 3 2 4 8 5 7 6 10 9
10
8 7 1 2 6 5 4 3 10 9
1...

output:

YES
NO
YES
YES
YES
YES
YES
YES
NO
NO

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

10
10
10 6 4 8 1 3 9 5 2 7
10
2 1 3 9 8 7 4 5 6 10
10
1 9 6 2 3 7 4 8 10 5
10
3 1 2 5 4 6 10 8 7 9
1...

output:

NO
YES
NO
YES
YES
YES
YES
YES
YES
YES

result:

ok 10 lines

Test #3:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

10
10
9 8 7 6 5 4 2 1 3 10
10
7 10 2 5 1 3 8 4 6 9
10
4 6 2 7 8 9 3 10 5 1
10
5 4 1 2 3 6 7 8 9 10
1...

output:

YES
NO
NO
YES
NO
NO
YES
NO
YES
YES

result:

ok 10 lines

Test #4:

score: 10
Accepted
time: 9ms
memory: 1632kb

input:

10
55985
29565 29563 29562 29352 29346 29328 29326 29325 29324 29323 29320 29319 29314 29313 29312 2...

output:

YES
NO
YES
YES
YES
YES
YES
NO
YES
NO

result:

ok 10 lines

Test #5:

score: 10
Accepted
time: 8ms
memory: 1548kb

input:

10
7763
3680 277 7608 5750 4337 7049 5804 3272 1940 4138 656 4368 3918 6305 3327 5872 4032 2233 5256...

output:

NO
YES
NO
YES
YES
NO
NO
YES
YES
YES

result:

ok 10 lines

Test #6:

score: 10
Accepted
time: 8ms
memory: 1752kb

input:

10
71974
28234 36059 56781 31385 50663 31905 45178 38510 58367 71478 55134 3951 16243 44225 5711 699...

output:

NO
YES
NO
NO
NO
YES
YES
YES
NO
NO

result:

ok 10 lines

Test #7:

score: 10
Accepted
time: 9ms
memory: 1588kb

input:

10
51542
1512 25827 42622 23126 27057 8283 46006 27813 21072 29589 10487 8260 37934 48675 27116 4708...

output:

NO
NO
YES
YES
YES
NO
NO
NO
YES
NO

result:

ok 10 lines

Test #8:

score: 10
Accepted
time: 10ms
memory: 1672kb

input:

10
61442
27627 49016 59575 37948 60082 14313 44305 48280 31222 36746 30283 42328 23889 42782 25771 4...

output:

NO
NO
NO
YES
YES
YES
NO
YES
YES
NO

result:

ok 10 lines

Test #9:

score: 10
Accepted
time: 7ms
memory: 1516kb

input:

10
17970
3118 3116 3114 3113 3108 3107 3106 2092 2091 2089 2088 2087 2085 2081 2080 2079 2077 2067 2...

output:

YES
YES
NO
NO
YES
NO
NO
YES
NO
YES

result:

ok 10 lines

Test #10:

score: 10
Accepted
time: 16ms
memory: 1700kb

input:

10
64613
49144 62298 12440 25315 54016 17872 58100 38381 41434 10557 57214 23632 29057 62471 48206 2...

output:

NO
YES
NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 10 lines