提交记录 2073


用户 题目 状态 得分 用时 内存 语言 代码长度
negiizhao 1003. 测测你的二分查找 Accepted 100 75.13 us 12 KB C 948 B
提交时间 评测时间
2018-06-21 17:28:32 2020-07-31 20:58:28
const int block_cnt = 24;

int guide[24];

#define g(i) guide[i] = a[n / block_cnt * i]
#define g0(x) g(x), g((x + 1)), g((x + 2))
#define g1(x) g0(x), g0((x + 3))
#define g2(x) g1(x), g1((x + 6))
#define g3(x) g2(x), g2((x + 12))

int init(const unsigned *a, const int n)
{
	g3(0);
	return 0;
}

#define w(i) p = a + n / block_cnt * i, n = n / block_cnt * (i + 1) - n / block_cnt * i - 1;
#define c(i, a, b) if (x < guide[i]) a else b
#define c0(x) c(x, w((x - 1)), c(x + 1, w(x), w((x + 1))))
#define c1(x) c(x, c0((x - 2)), c0((x + 1)))
#define c2(x) c(x, c1((x - 3)), c1((x + 3)))
#define c3(x) c(x, c2((x - 6)), c2((x + 6)))

int binary_search(const unsigned *a, int n, const unsigned x)
{
	static int _ = 1;
	if (_)
		init(a, n), _ = 0;
	
	const unsigned *p;
	
	c3(12);
	
	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 #175.13 us12 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-21 05:35:00 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠