QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426734#5029. 在路上Richard_whr20 878ms49748kbC++203.4kb2024-05-31 18:46:182024-05-31 18:46:19

Judging History

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

  • [2024-05-31 18:46:19]
  • 评测
  • 测评结果:20
  • 用时:878ms
  • 内存:49748kb
  • [2024-05-31 18:46:18]
  • 提交

answer

#include"path.h"
#include<bits/stdc++.h>
using namespace std;
const int N=5e4+10;
int n,m,L,R,szl,szr,wc;
int bel[N],p[N];
vector<int> Link,ctr;
mt19937 rnd(time(0));
int rand(int l,int r)
{
	return rnd()%(r-l+1)+l;
}

//int ask(int a,int b,int c)
//{
//	return 0;
//}

int get_fa(int u)
{
	if(bel[u]==u) return u;
	int fa=0;
	for(auto x:Link)
	{
		if(!fa) fa=x;
		else fa=ask(fa,u,x);
	}
	return fa;
} 

int check(int x,int lc,int rc)//把x子树中的点拿出来,投出来x子树大小最大的儿子 ,每次询问(now,x,y)可以知道now和y是否在一棵子树 
{
	int cnt=0,now=0;
	if(lc!=rc)cnt=abs(lc-rc),now=lc>rc?L:R;
	for(auto y:ctr)if(x!=y&&bel[y]==-1)
		if(!now||ask(now,x,y)!=x)now=!now?y:now,cnt++;
		else if(--cnt==0)now=0;
	if(!now||now==L||now==R)return 1;//如果没有绝对众数 
	cnt=0;
	for(auto y:ctr)if(x!=y&&bel[y]==-1)if(y==now||ask(x,now,y)!=x)cnt++;//统计一下和他在一棵子树内的部分 
	return cnt*2<=n;
}
//
//int solve()
//{
//	if(L==R||ctr.size()==0) return 0;
//	vector<int> vec;vec=ctr;
//	ctr.clear(),Link.clear();
//	for(auto x:vec)
//	{
//		if(x==L||x==R) continue;
//		bel[x]=ask(L,x,R);
//		if(bel[x]==L) szl++;
//		else if(bel[x]==R) szr++;
//		else if(bel[x]==x) Link.push_back(x),ctr.push_back(x);
//		else ctr.push_back(x); 
//	} 
//	if(szl*2>n||szr*2>n) return 0;
//	int nw=get_fa(ctr[rand(0,ctr.size()-1)]);
//	int lc=szl,rc=szr;
//	for(auto x:ctr)
//	{
//		if(x==nw) continue;
//		if(ask(x,L,nw)!=nw) bel[x]=0,lc++;
//		else if(ask(x,R,nw)!=nw) bel[x]=1,rc++;
//		else bel[x]=-1;  	
//	} 
//	if(lc*2<=n&&rc*2<=n&&check(nw,lc,rc)) return nw;
//	if(lc>rc) R=nw,szr++;
//	else L=nw,szl++;
//	return solve(); 
//}

int solve()
{
	if(L==R||!ctr.size())return 0;
	vector<int> vt(ctr);
	ctr.clear();//不在链两端子树中的点集 
	Link.clear();//在链上的点集 
	for(auto x:vt)
	{
		if(x==L||x==R)continue;
		bel[x]=ask(L,x,R);//标记属于l的子树,r的子树或链上的点 
		if(bel[x]==L) szl++;//在链左端的点 
		else if(bel[x]==R)szr++;//在链右端的点 
		else if(bel[x]==x) Link.push_back(x),ctr.push_back(x);//正好在链上的点 
		else ctr.push_back(x);//不在链上的点且不是左右两端子树中的 
	}
	if(szl*2>n||szr*2>n)return 0;//左右两子树已经超限 
	uniform_int_distribution<int>dist(0,ctr.size()-1);
	int nw=get_fa(ctr[dist(rnd)]);//随机在链上选一个不在两端的点 
	int lc=szl,rc=szr;
	for(auto x:ctr)//统计p链左子树大小和p链右子树大小 
	{
		if(x==nw)continue;
		if(ask(x,L,nw)!=nw) bel[x]=0,lc++;//在链上p左侧的子树中 
		else if(ask(x,R,nw)!=nw) bel[x]=1,rc++;//在链上p右侧的子树中 
		else bel[x]=-1;//恰在p的子树内 
	}
	if(lc*2<=n&&rc*2<=n)if(check(nw,lc,rc))return nw;
	if(lc>rc)R=nw,szr++;else L=nw,szl++;//往子树大小大的方向移动 
	return solve();
}

int centroid(int id,int N,int M)
{
	n=N,m=M;
	if(id==5)
	{
		int a=1,b=2;
		p[1]=1,p[2]=2;
		for(int i=3;i<=n;i++)
		{	
			p[i]=i;
			int mid=ask(a,b,i);
			if(mid==a) a=i;
			else if(mid==b) b=i;
		}
		nth_element(p+1,p+n/2+1,p+n+1,[=](const int&x,const int&y){return ask(a,x,y)!=x;});
		return p[n/2+1];
	}
	if(n==3) return ask(1,2,3);
	while(true)
	{
		Link.clear();
		L=rand(1,n),R=rand(1,n);
		for(int u=1;u<=n;u++) 
		{
			if(u!=L&&u!=R) ctr.push_back(u);
		}
		szl=szr=1;
		if((wc=solve())) return wc;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 2
Accepted

Test #1:

score: 2
Accepted
time: 1ms
memory: 9936kb

input:

1 100 100
3
1 2
3
1 2
3
3 1
3
1 2
3
1 2
3
3 1
3
1 2
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
...

result:

ok correct

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 183ms
memory: 12164kb

input:

2 10 10000000
999
60 112 98 509 586 175 588 875 861 516 920 370 781 249 999 649 292 308 934 949 437 92 506 752 547 866 869 510 984 228 104 612 202 630 360 809 56 107 566 448 940 726 146 299 941 50 319 794 670 603 365 492 728 872 829 942 451 632 373 106 909 25 306 995 735 99 568 673 75 573 383 407 56...

result:

wrong answer too many queries

Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 169ms
memory: 16248kb

input:

3 100 10000000
999
328 852 537 953 554 506 483 192 443 912 989 346 935 232 652 528 261 899 131 531 81 686 815 543 991 810 576 639 670 572 604 842 546 322 916 97 510 160 238 696 882 214 212 194 102 964 719 255 416 260 687 148 225 664 105 100 913 600 921 203 571 406 752 189 929 716 523 809 666 589 235...

result:

wrong answer too many queries

Subtask #4:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 170ms
memory: 14392kb

input:

4 100 10000000
999
710 227 715 954 623 585 538 236 363 913 540 3 897 998 726 919 976 843 796 69 415 705 647 707 201 696 993 545 325 375 47 260 490 385 828 162 29 278 867 593 395 219 178 518 999 685 307 772 224 187 557 89 575 524 1 157 230 341 708 978 473 995 15 179 743 416 263 640 4 851 520 719 679 ...

result:

wrong answer too many queries

Subtask #5:

score: 18
Accepted

Test #47:

score: 18
Accepted
time: 753ms
memory: 49688kb

input:

5 100 25000000
49999
3753 28650 36024 8322 47241 9061 43764 6338 45160 16765 40294 43358 37214 37535 38561 1997 7478 9543 11661 1953 7391 41171 43559 9981 24218 13155 22152 45216 30123 1843 20703 23601 42707 6449 40356 3761 32284 34584 32674 44391 41031 324 14845 6935 37071 38330 48041 1824 41182 46...

result:

ok correct

Test #48:

score: 18
Accepted
time: 754ms
memory: 49028kb

input:

5 100 25000000
49999
4355 37348 38321 35425 21214 5083 45595 40224 33795 7313 23253 7272 29677 28728 35487 1991 44807 19910 7658 37652 35455 2514 34837 45354 38770 33373 22354 33923 553 32137 13158 39583 34278 32253 41652 2024 4250 27447 26990 40809 10542 48821 40099 43201 16468 13915 18394 17223 14...

result:

ok correct

Test #49:

score: 18
Accepted
time: 749ms
memory: 49748kb

input:

5 100 25000000
49999
35421 12483 27611 26116 3078 41676 32102 20450 46565 7259 31701 39279 7716 18095 574 6832 14245 45403 7403 28959 10895 7192 24221 15536 28096 37220 49443 18168 43803 27863 7445 1555 2310 26797 44390 32627 34653 10091 41373 19105 11758 6420 21895 2662 5651 5357 8564 30178 47283 3...

result:

ok correct

Test #50:

score: 18
Accepted
time: 757ms
memory: 49380kb

input:

5 100 25000000
49999
42046 19387 33162 23626 9528 41604 26357 27547 18587 20216 43658 5642 12752 36928 460 17925 6866 9380 29791 10256 12103 24116 39054 21861 14347 21118 23852 31261 10246 23316 46935 39281 41944 47820 43306 25162 42713 17257 29474 32926 12743 18125 14549 23818 22784 22008 37108 364...

result:

ok correct

Test #51:

score: 18
Accepted
time: 741ms
memory: 48924kb

input:

5 100 25000000
49999
47176 35953 43451 38072 40586 17234 18319 28218 37190 15923 25135 40310 27316 17131 2164 26393 41753 47710 22396 27790 22627 49297 10917 11986 44920 27629 27944 14780 16282 11016 36590 34850 43230 85 27951 1338 3203 33927 49761 49552 16274 3167 49305 34706 25494 47457 14679 2608...

result:

ok correct

Subtask #6:

score: 0
Wrong Answer

Test #52:

score: 0
Wrong Answer
time: 684ms
memory: 21208kb

input:

6 100 40000000
9999
3929 7460 4617 7377 498 7572 4628 3661 2404 9179 755 4076 8531 6581 1929 9419 1498 4402 6412 712 4918 2628 798 6283 9427 9775 1472 5554 2146 9972 5228 5459 8417 6778 3121 7649 1031 7691 6270 2238 4885 6121 2099 3435 4615 9962 6384 8809 9169 4553 66 1939 8589 2029 4897 7334 2867 8...

result:

wrong answer too many queries

Subtask #7:

score: 0
Wrong Answer

Test #72:

score: 0
Wrong Answer
time: 728ms
memory: 27204kb

input:

7 50 40000000
29999
12447 18709 13054 17585 8337 14953 7985 1930 24383 1787 2543 26860 12198 2842 14256 8665 17034 6429 14773 8646 27093 6362 29357 18001 10667 8445 6671 21435 27163 14604 19875 745 20772 6696 16391 15560 16789 10983 6199 23133 13 13688 14547 8390 4398 21653 14460 690 24385 5358 2213...

result:

wrong answer too many queries

Subtask #8:

score: 0
Wrong Answer

Test #92:

score: 0
Wrong Answer
time: 878ms
memory: 36464kb

input:

8 100 50000000
29999
8375 16777 16700 20953 11899 14682 20874 25860 28858 23241 5089 8044 25448 17746 5605 3087 9145 20179 1080 22944 27383 8384 19943 15371 27572 7882 23028 10474 18744 20202 15687 17001 7543 18709 23165 15713 17032 29011 22353 17455 26045 3484 20330 15159 21274 382 23927 20114 6303...

result:

wrong answer too many queries