提交记录 6136


用户 题目 状态 得分 用时 内存 语言 代码长度
luohy15 1001. 测测你的排序 Runtime Error 0 1.247 s 390888 KB C++11 1.18 KB
提交时间 评测时间
2018-09-28 00:14:51 2020-08-01 00:39:40
//****************************************************************************
// BEGIN INT SORT
//
// Problem: sort an array of 32 bit integers as fast as possible.
//
// Basic idea:
//	First sort the lower 16 bits using radix sort (O(65536) + O(n)), 
//	then sort the higher 16 bits stably using radix sort (O(65536) + O(n))

// CONFIG:
#define MAX_N 100000017

// IMPL:
#define l16(a) ((a)&65535)
#define h16(a) (((unsigned)(a))>>16)
unsigned cnt[65536];
unsigned store[MAX_N];

static inline void pass1(unsigned* a, unsigned n) {
	for (unsigned i = 0; i < 65536; i++) cnt[i] = 0;
	for (unsigned i = 0; i < n; i++) cnt[l16(a[i])]++;
	for (unsigned i = 1; i < 65536; i++) cnt[i] += cnt[i-1];
	for (unsigned i = n-1; i >= 0; i--) store[--cnt[l16(a[i])]] = a[i];
}

static inline void pass2(unsigned* a, unsigned n) {
	for (unsigned i = 0; i < 65536; i++) cnt[i] = 0;
	for (unsigned i = 0; i < n; i++) cnt[h16(a[i])]++;
	for (unsigned i = 1; i < 65536; i++) cnt[i] += cnt[i-1];
	for (unsigned i = n-1; i >= 0; i--) a[--cnt[h16(store[i])]] = store[i];
}

void sort(unsigned* a, int n) {
	pass1(a, n);
	pass2(a, n);
}

// END INT SORT
//****************************************************************************

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.247 s381 MB + 744 KBRuntime ErrorScore: 0


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