提交记录 6135


用户 题目 状态 得分 用时 内存 语言 代码长度
luohy15 1001. 测测你的排序 Runtime Error 0 1.462 s 391144 KB C++11 1.16 KB
提交时间 评测时间
2018-09-28 00:00:17 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:
#include <cstring>
#define l16(a) ((a)&65535)
#define h16(a) (((unsigned)(a))>>16)
size_t cnt[65536];
unsigned store[MAX_N];

static inline void pass1(unsigned* a, size_t n) {
	memset(cnt, 0, sizeof(cnt));
	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, size_t n) {
	memset(cnt, 0, sizeof(cnt));
	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.462 s381 MB + 1000 KBRuntime ErrorScore: 0


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