UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#200908#3478. selectAndyLuo100746ms20716kbC++1018b2024-01-14 10:53:562024-01-14 12:18:26

answer

#include <bits/stdc++.h>
using namespace std;
int n,k,a[1000050],pre[1000050],nxt[1000050],pl[1000050],top,posa,posb,cnt,ans[1000050];
int main()
{
	scanf("%d%d",&n,&k);
	for (int i = 1;i <= n;i++)
	{
		scanf("%d",a + i);
		pre[i] = i - 1;
		nxt[i] = i + 1;
		pl[a[i]] = i;
	}
	pre[1] = n;
	nxt[n] = 1;
	top = n;
	while (top)
	{
		if (pl[top] != -1)
		{
			cnt++;
//			printf("%d ",pl[top]);
			posa = posb = pl[top];
			ans[pl[top]] = cnt;
			pl[top] = -1;
			for (int i = 1;i <= k;i++)
			{
				posa = pre[posa];
				if (pl[a[posa]] == -1)
					break;
				pl[a[posa]] = -1;
				ans[posa] = cnt;
//				printf("%d ",posa);
			}
			for (int i = 1;i <= k;i++)
			{
				posb = nxt[posb];
				if (pl[a[posb]] == -1)
					break;
				pl[a[posb]] = -1;
				ans[posb] = cnt;
//				printf("%d ",posb);
			}
//			printf("\n");
			int x = pre[posa],y = nxt[posb];
			nxt[x] = y;
			pre[y] = x;
		}
		top--;
	}
	for (int i = 1;i <= n;i++)
		printf("%d ",ans[i]);
	return 0;
}

详细

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

Test #1:

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

input:

500 5
393 398 108 117 84 445 14 451 142 53 50 449 491 196 365 488 303 46 429 300 57 348 189 141 293 ...

output:

28 28 28 28 32 32 32 9 9 9 9 9 9 9 9 9 9 9 32 32 32 32 45 29 29 29 29 29 3 3 3 3 3 3 3 3 3 3 3 29 29...

result:

ok single line: '28 28 28 28 32 32 32 9 9 9 9 9... 32 32 32 28 28 28 28 28 28 28 '

Test #2:

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

input:

800 4
732 529 460 536 20 397 470 705 723 571 471 95 578 613 582 522 734 312 751 631 260 510 170 72 4...

output:

50 50 50 50 50 54 54 54 54 54 54 54 54 82 39 39 39 39 39 39 39 39 39 82 82 82 82 86 86 86 25 25 25 2...

result:

ok single line: '50 50 50 50 50 54 54 54 54 54 ... 48 48 48 48 48 48 50 50 50 50 '

Test #3:

score: 10
Accepted
time: 1ms
memory: 1224kb

input:

999 11
425 709 285 798 610 394 18 777 62 828 101 891 726 204 19 609 933 655 812 593 819 668 651 201 ...

output:

35 35 35 35 41 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 41 41 25 25 25 2...

result:

ok single line: '35 35 35 35 41 36 36 36 36 36 ...3 3 3 3 3 3 3 3 26 26 31 31 35 '

Test #4:

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

input:

10000 15
2086 7229 9314 8859 8892 6883 9696 6205 6211 9028 4238 3319 4458 628 6552 9063 6006 6262 52...

output:

98 98 98 98 98 98 98 98 98 98 98 98 291 291 291 291 291 291 31 31 31 31 31 31 31 31 31 31 31 31 31 3...

result:

ok single line: '98 98 98 98 98 98 98 98 98 98 ... 98 98 98 98 98 98 98 98 98 98 '

Test #5:

score: 10
Accepted
time: 5ms
memory: 2180kb

input:

50000 98
7734 8076 7492 15131 23605 19303 36490 48940 27537 48475 38921 45541 43382 17930 48109 2583...

output:

18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 1...

result:

ok single line: '18 18 18 18 18 18 18 18 18 18 ... 18 18 18 18 18 18 18 18 18 18 '

Test #6:

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

input:

100000 76
96269 74627 80621 86094 91844 92348 99721 7372 26125 85969 94067 76051 63209 71619 39296 7...

output:

78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 4...

result:

ok single line: '78 78 78 78 78 78 78 78 78 78 ... 78 78 78 78 78 78 78 78 78 78 '

Test #7:

score: 10
Accepted
time: 83ms
memory: 10972kb

input:

500000 207
371252 499715 480852 496545 461421 476775 450423 491323 479946 497396 497165 485618 47794...

output:

66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 6...

result:

ok single line: '66 66 66 66 66 66 66 66 66 66 ... 66 66 66 66 66 66 66 66 66 66 '

Test #8:

score: 10
Accepted
time: 150ms
memory: 16832kb

input:

800000 425
785370 745167 785362 737709 718450 769221 792379 760938 796936 732010 796002 717915 79418...

output:

14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 1...

result:

ok single line: '14 14 14 14 14 14 14 14 14 14 ... 14 14 14 14 14 14 14 14 14 14 '

Test #9:

score: 10
Accepted
time: 165ms
memory: 20716kb

input:

999999 444
954211 992764 974842 986560 968768 992439 995281 999962 970289 975438 982780 985393 99697...

output:

25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 2...

result:

ok single line: '25 25 25 25 25 25 25 25 25 25 ... 25 25 25 25 25 25 25 25 25 25 '

Test #10:

score: 10
Accepted
time: 326ms
memory: 20716kb

input:

1000000 277
956112 974080 948497 979521 952353 962692 955605 995542 989620 978231 998101 985593 9998...

output:

55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 5...

result:

ok single line: '55 55 55 55 55 55 55 55 55 55 ... 55 55 55 55 55 55 55 55 55 55 '