提交记录 1990


用户 题目 状态 得分 用时 内存 语言 代码长度
alphaGem 1003. 测测你的二分查找 Accepted 100 180.28 us 12 KB C 589 B
提交时间 评测时间
2018-06-21 14:45:38 2020-07-31 20:57:18
int gmax(register int a,register int b){return a>b?a:b;}
int gmin(register int a,register int b){return a<b?a:b;}
int binary_search(unsigned *a,int n,register unsigned x)
{
	int p=1ll*n*x/a[n-1],lim=16;
	if(x<=a[p])
	{
		for(;a[gmax(p-lim,0)]>x;lim<<=1);
		register int l=gmax(p-lim,0),r=p;
		do
		{
			register int mid=(l+r)>>1;
			(a[mid]<x)?(l=mid+1):(r=mid);
		}
		while(l!=r);
		return l;
	}
	else
	{
		for(;x>a[gmin(p+lim,n-1)];lim<<=1);
		register int l=p,r=gmin(p+lim,n-1);
		do
		{
			register int mid=(l+r)>>1;
			(a[mid]<x)?(l=mid+1):(r=mid);
		}
		while(l!=r);
		return l;
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1180.28 us12 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-24 02:50:34 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠