提交记录 13824


用户 题目 状态 得分 用时 内存 语言 代码长度
CraZYali 1001. 测测你的排序 Accepted 100 853.407 ms 781292 KB C++ 1.18 KB
提交时间 评测时间
2020-08-11 17:24:06 2020-08-11 17:24:11
/*
	Problem:	1001.cpp
	Time:		2020-08-11 16:02
	Author:		CraZYali
	E-Mail:		yms-chenziyang@outlook.com 
*/

#define file(FILE_NAME) freopen(FILE_NAME".in", "r", stdin), freopen(FILE_NAME".out", "w", stdout)

#include <iostream>
#include <cstdio>

#define work(w)\
{\
	for (int i = 0; i < n; i++) cnt[a[i] >> w & B]++;\
	str[0] = pool;\
	for (int i = 0; i < B; i++) str[i + 1] = str[i] + cnt[i], cnt[i] = 0;\
	for (int i = 0; i < n; i++) *(str[a[i] >> w & B]++) = a[i];\
}
const int w = 8, B = (1 << w) - 1;

const int maxn = 100000000;
int cnt[B + 1];
unsigned *pool, *str[B + 1];


void sort(unsigned *a, int n)
{
	pool = new unsigned[n];
	int w = 0;
	{
		for (int i = 0; i < n; i++) cnt[a[i] & B]++;
		str[0] = pool;
		for (int i = 0; i < B; i++) str[i + 1] = str[i] + cnt[i], cnt[i] = 0;
		for (int i = 0; i < n; i++) *(str[a[i] & B]++) = a[i];
		std :: swap(a, pool);
	}
	work(8);
	std :: swap(a, pool);

	work(16);
	std :: swap(a, pool);

	work(24);
	a = pool;
}

#ifdef CraZYali
unsigned a[maxn];
int main()
{
	file("1001");
	int n;scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%u", a + i);
	sort(a, n);
	for (int i = 0; i < n; i++) printf("%u%c", a[i], i == n - 1 ? '\n' : ' ');
	return 0;
}
#endif

CompilationN/AN/ACompile OKScore: N/A

Testcase #1853.407 ms762 MB + 1004 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-23 16:27:39 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠