QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519578#8212. Football in OsijekYoralenWA 96ms44380kbC++141.8kb2024-08-14 21:52:162024-08-14 21:52:21

Judging History

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

  • [2024-08-14 21:52:21]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:44380kb
  • [2024-08-14 21:52:16]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int N=500005;
int a[N],n,T,fm[N],st[N],tp,vis[N],tg[N],son[N],h[N];
int cf[N],ans[N],mx,mxx,val[N],ti,I,cl[N],d[N],md[N],cnt;
struct edge{int to,next;}w[N<<1];
vector<int>C[N];
struct node{int to,next;};
void Add(int x,int y){
//	printf("%d %d\n",x,y);
	w[++cnt].to=y,w[cnt].next=h[x],h[x]=cnt;
}
void Fnd(int x){
	st[++tp]=x;vis[x]=ti;
	if(!vis[a[x]])Fnd(a[x]);
	else{
		if(vis[a[x]]!=ti)return;
		int y,c=0;I++;
		do{y=st[tp];cl[y]=I;tp--,C[I].push_back(y);}while(y!=a[x]);
		return;
	}
}
void DFS1(int u,int ff){
	d[u]=d[ff]+val[u];md[u]=d[u];
	for(int i=h[u];i;i=w[i].next){
		int e=w[i].to;
		if(e==ff)continue;DFS1(e,u);
		if(md[e]>md[son[u]])son[u]=e;
		md[u]=max(md[u],md[e]);
	}
}
void DFS2(int u,int dp){
	if(son[u])DFS2(son[u],dp+val[son[u]]);
	else st[++tp]=dp,mx=max(mx,dp);
	for(int i=h[u];i;i=w[i].next){
		int e=w[i].to;
		if(e!=son[u])DFS2(e,val[e]);
	}
}
bool cmp(int a,int b){return a>b;}
int main(){
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++){if(!vis[i]){tp=0;ti++;Fnd(i);}}
	for(i=1;i<=n;i++){
		if(cl[i])continue;
		if(cl[a[i]])Add(cl[a[i]]+n,i);
		else Add(a[i],i);
	}
	for(i=1;i<=n;i++)val[i]=1;tp=0;
	for(i=n+1;i<=n+I;i++)val[i]=C[i-n].size();
	for(i=n+1;i<=n+I;i++){
		mx=0;DFS1(i,0);DFS2(i,val[i]);
		cf[val[i]]++;cf[mx+1]--;
		mxx=max(mxx,mx);
	}
	for(i=1;i<=n;i++){
		cf[i]+=cf[i-1];
		if(cf[i])ans[i]=0,tg[i]=1;
		else if(i<=mxx)ans[i]=1,tg[i]=1;
	}
	sort(st+1,st+1+tp,cmp);
	
//	for(i=1;i<=tp;i++)printf("!%d\n",st[i]); 
	int sc=0;
	for(i=1;i<=tp;i++)sc+=st[i],fm[sc]=i-1;
	for(i=n;i>=1;i--){
		if(!fm[i])fm[i]=fm[i+1];
	}
	for(i=1;i<=n;i++){
		if(!tg[i])ans[i]=fm[i];
		printf("%d ",ans[i]);
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 32196kb

input:

5
2 3 1 3 5

output:

0 1 0 0 1 

result:

ok 5 number(s): "0 1 0 0 1"

Test #2:

score: 0
Accepted
time: 2ms
memory: 30656kb

input:

1
1

output:

0 

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 3ms
memory: 33872kb

input:

2
2 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 30812kb

input:

10
4 7 2 8 4 3 4 9 7 3

output:

1 1 1 0 0 0 0 1 2 3 

result:

ok 10 numbers

Test #5:

score: 0
Accepted
time: 3ms
memory: 33648kb

input:

10
8 7 4 8 3 4 2 5 3 7

output:

1 0 0 0 0 1 1 1 2 3 

result:

ok 10 numbers

Test #6:

score: 0
Accepted
time: 0ms
memory: 30548kb

input:

10
7 1 4 1 6 1 1 10 5 7

output:

1 0 0 0 0 1 1 2 2 3 

result:

ok 10 numbers

Test #7:

score: 0
Accepted
time: 0ms
memory: 32984kb

input:

10
5 6 1 3 6 4 3 9 3 2

output:

1 1 1 1 0 0 0 1 1 2 

result:

ok 10 numbers

Test #8:

score: 0
Accepted
time: 0ms
memory: 33552kb

input:

10
10 4 3 6 5 10 7 5 6 6

output:

0 0 0 0 1 1 2 3 4 5 

result:

ok 10 numbers

Test #9:

score: 0
Accepted
time: 3ms
memory: 32088kb

input:

10
10 9 10 10 8 3 5 10 2 5

output:

1 0 0 0 0 1 1 2 3 4 

result:

ok 10 numbers

Test #10:

score: 0
Accepted
time: 7ms
memory: 33780kb

input:

10
1 9 7 6 2 4 7 8 1 3

output:

0 0 0 0 1 1 1 2 2 3 

result:

ok 10 numbers

Test #11:

score: 0
Accepted
time: 3ms
memory: 30344kb

input:

10
3 9 4 10 9 5 5 1 3 2

output:

1 1 1 1 0 0 0 1 1 2 

result:

ok 10 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 33536kb

input:

100
55 62 70 100 90 98 69 1 93 8 98 86 12 1 47 95 12 35 38 59 57 60 54 34 12 17 34 51 70 32 92 47 22 42 55 88 19 74 58 43 56 80 67 86 30 14 93 87 93 58 19 19 59 82 30 68 56 87 55 92 29 87 19 71 65 40 20 65 43 94 22 62 77 40 4 32 90 88 7 40 86 30 59 9 25 93 38 20 59 23 79 10 71 92 72 25 59 86 72 44

output:

0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 8 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 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 

result:

ok 100 numbers

Test #13:

score: 0
Accepted
time: 6ms
memory: 33784kb

input:

1000
108 318 583 10 344 396 385 989 298 514 936 308 167 510 61 175 760 840 33 576 481 535 643 128 682 755 693 51 209 228 79 56 111 10 179 538 398 530 751 337 770 160 790 506 901 735 367 299 760 58 205 896 729 615 213 593 767 375 723 97 272 552 181 305 693 707 886 202 400 462 725 87 332 434 707 217 5...

output:

1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 ...

result:

ok 1000 numbers

Test #14:

score: 0
Accepted
time: 2ms
memory: 33872kb

input:

10000
8466 8125 3435 8586 3368 6364 6214 8960 2364 2387 4607 3236 8618 6499 1662 2415 7751 8495 1984 3727 6713 6526 5478 7446 1114 5229 5268 8714 4041 9738 819 6324 328 6874 2655 2673 9663 7667 4809 8660 4920 3059 6470 322 8945 1015 4766 1892 7037 9541 5502 4168 2851 5491 2550 4993 9885 1117 5436 74...

output:

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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

ok 10000 numbers

Test #15:

score: 0
Accepted
time: 17ms
memory: 31500kb

input:

100000
89736 90728 95214 56421 59309 36615 29493 69816 65743 86382 7094 42018 28261 7523 64050 99816 26139 7011 98078 65853 84622 85470 47458 72747 77008 42294 49212 1553 2794 70980 13082 53696 11317 19251 1987 15965 14848 45027 80911 6851 34830 91975 3178 2174 8533 35176 27893 61328 3295 57023 7078...

output:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 ...

result:

ok 100000 numbers

Test #16:

score: 0
Accepted
time: 45ms
memory: 37192kb

input:

200000
15136 43638 172383 6589 42364 26506 86708 33565 32298 2140 104626 6147 112684 106455 3861 62177 180185 27354 44651 5922 85017 16759 117594 93474 120042 190324 152024 171698 93854 134285 88626 97878 91419 123632 155398 78342 67801 162879 92936 82736 110376 192466 146753 163060 17127 139122 382...

output:

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 0 0 ...

result:

ok 200000 numbers

Test #17:

score: 0
Accepted
time: 52ms
memory: 39404kb

input:

300000
248727 238625 33448 169223 121934 209881 193446 156493 65642 230647 81702 145630 87210 102610 165536 14973 238945 230552 108740 68192 232183 152168 45457 47153 130600 294649 286335 299281 129635 262962 6902 253328 284523 191279 112917 15702 26650 253987 273484 80574 147225 14832 236866 256949...

output:

0 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 1 1 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 ...

result:

ok 300000 numbers

Test #18:

score: 0
Accepted
time: 85ms
memory: 40972kb

input:

400000
98318 300047 10618 95199 204989 99772 359174 363347 132197 13701 344642 101246 295825 25734 162243 310038 125695 375086 55313 316773 332578 283457 215593 192072 73633 142679 264956 379825 20695 202074 149742 64806 388817 228364 290519 302271 355411 180351 61317 156459 90067 239515 80440 18513...

output:

0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 ...

result:

ok 400000 numbers

Test #19:

score: -100
Wrong Answer
time: 96ms
memory: 44380kb

input:

500000
323718 428765 255083 245367 344940 498175 424901 27097 222944 229460 374878 465374 80247 424666 302053 348208 479741 62725 334590 189547 257165 225146 318433 12799 416667 290708 367769 349970 187562 341187 325285 41691 368918 122344 143930 164648 208364 330907 240639 223833 465613 72709 12401...

output:

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 0 0 ...

result:

wrong answer 1827th numbers differ - expected: '1', found: '0'