提交记录 22607


用户 题目 状态 得分 用时 内存 语言 代码长度
TSKY 1003. 测测你的二分查找 Accepted 100 338.43 us 12 KB C++14 826 B
提交时间 评测时间
2024-10-19 18:37:14 2024-10-19 18:37:17
constexpr int BOLCKS = 64;
int table[BOLCKS];

void init(const unsigned *a, int n)
{
	static bool is_init = false;
	if (!is_init)
	{
		is_init = true;
		const int block_len = n / BOLCKS;
		for (int i = 0; i < BOLCKS; ++i)
		{
			table[i] = a[block_len * i];
		}
	}
}

int search_block(const unsigned x)
{
	int l = -1, r = BOLCKS, m = (l + r) / 2;
	while (m > l)
	{
		if (table[m] > x)
		{
			r = m;
		}
		else
		{
			l = m;
		}
		m = (l + r) / 2;
	}
	return l;
}

int binary_search(const unsigned *a, int n, const unsigned x)
{
	init(a, n);
	const int block_len = n / BOLCKS;
	int l = search_block(x), r = l + 1;
	l *= block_len;
	if (r == BOLCKS)
	{
		r = n;
	}
	else
	{
		r *= block_len;
	}
	int m = (l + r) / 2;
	while (m > l)
	{
		if (a[m] > x)
		{
			r = m;
		}
		else
		{
			l = m;
		}
		m = (l + r) / 2;
	}
	return l;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1338.43 us12 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2025-07-12 01:40:15 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠