提交记录 2242


用户 题目 状态 得分 用时 内存 语言 代码长度
Simpson561 1003. 测测你的二分查找 Accepted 100 69.32 us 12 KB C 889 B
提交时间 评测时间
2018-06-22 19:37:38 2020-07-31 21:00:26
const int block_cnt = 16;

int guide[16];

#define g(i) guide[i] = a[n / block_cnt * i]

int init(const unsigned *a, const int n)
{
	g(1), g(2), g(3), g(4), g(5), g(6), g(7), g(8), g(9), g(10), g(11), g(12), g(13), g(14), g(15);
	return 0;
}

#define c(i, a, b) if (x < guide[i]) a else b
#define w(i) p = a + n / block_cnt * i, n = n / block_cnt * (i + 1) - n / block_cnt * i - 1;

int binary_search(const unsigned *a, int n, const unsigned x)
{
	static int _ = 1;
	if (_)
		init(a, n), _ = 0;
	
	const unsigned *p;
	
	c(8, c(4, c(2, c(1, w(0), w(1)), c(3, w(2), w(3))), c(6, c(5, w(4), w(5)), c(7, w(6), w(7)))), c(12, c(10, c(9, w(8), w(9)), c(11, w(10), w(11))), c(14, c(13, w(12), w(13)), c(15, w(14), w(15)))))
	
	int mid;
	--n;
	while (p[n] != x)
		if (mid = (n * (long long)(x - *p) / (p[n] - *p)), p[mid] < x)
			p += mid + 1, n -= mid + 1;
		else
			n = mid;
	return p - a + n;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #169.32 us12 KBAcceptedScore: 100


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