提交记录 17448


用户 题目 状态 得分 用时 内存 语言 代码长度
lotus_f 1001. 测测你的排序 Accepted 100 913.763 ms 781284 KB C++ 2.82 KB
提交时间 评测时间
2022-02-27 14:21:11 2022-02-27 14:21:17
#include<bits/stdc++.h>
using namespace std;

unsigned b[100000001];

void sort(unsigned *a, int n) {
	int cnt[256];
	memset(cnt,0,sizeof(cnt));
	for(int i=n-1; i>=0; --i) a[i+1]=a[i];
	//memcpy(a+1,a,n*4+4);
	register unsigned i, pw = 0;
	for (i = 1; i <= n - 3; i += 4)
		++cnt[(a[i] >> pw) & 255], ++cnt[(a[i + 1] >> pw) & 255], ++cnt[(a[i + 2] >> pw) & 255], ++cnt[(a[i + 3] >> pw) & 255];
	while (i <= n)
		++cnt[(a[i++] >> pw) & 255];
	for (i = 1; i < 256 - 3; i += 4)
		cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
	while (i < 256)
		cnt[i] += cnt[i - 1], ++i;
	for (i = n; i >= 1 + 3; i -= 4)
		b[cnt[(a[i] >> pw) & 255]--] = a[i], b[cnt[(a[i - 1] >> pw) & 255]--] = a[i - 1],
		b[cnt[(a[i - 2] >> pw) & 255]--] = a[i - 2], b[cnt[(a[i - 3] >> pw) & 255]--] = a[i - 3];
	while (i >= 1)
		b[cnt[(a[i] >> pw) & 255]--] = a[i], --i;
	pw += 8;
	memset(cnt, 0, sizeof(cnt));
	for (i = 1; i <= n - 3; i += 4)
		++cnt[(b[i] >> pw) & 255], ++cnt[(b[i + 1] >> pw) & 255], ++cnt[(b[i + 2] >> pw) & 255], ++cnt[(b[i + 3] >> pw) & 255];
	while (i <= n)
		++cnt[(b[i++] >> pw) & 255];
	for (i = 1; i < 256 - 3; i += 4)
		cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
	while (i < 256)
		cnt[i] += cnt[i - 1], ++i;
	for (i = n; i >= 1 + 3; i -= 4)
		a[cnt[(b[i] >> pw) & 255]--] = b[i], a[cnt[(b[i - 1] >> pw) & 255]--] = b[i - 1],
		a[cnt[(b[i - 2] >> pw) & 255]--] = b[i - 2], a[cnt[(b[i - 3] >> pw) & 255]--] = b[i - 3];
	while (i >= 1)
		a[cnt[(b[i] >> pw) & 255]--] = b[i], --i;
	pw += 8;
	memset(cnt, 0, sizeof(cnt));
	for (i = 1; i <= n - 3; i += 4)
		++cnt[(a[i] >> pw) & 255], ++cnt[(a[i + 1] >> pw) & 255], ++cnt[(a[i + 2] >> pw) & 255], ++cnt[(a[i + 3] >> pw) & 255];
	while (i <= n)
		++cnt[(a[i++] >> pw) & 255];
	for (i = 1; i < 256 - 3; i += 4)
		cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
	while (i < 256)
		cnt[i] += cnt[i - 1], ++i;
	for (i = n; i >= 1 + 3; i -= 4)
		b[cnt[(a[i] >> pw) & 255]--] = a[i], b[cnt[(a[i - 1] >> pw) & 255]--] = a[i - 1],
		b[cnt[(a[i - 2] >> pw) & 255]--] = a[i - 2], b[cnt[(a[i - 3] >> pw) & 255]--] = a[i - 3];
	while (i >= 1)
		b[cnt[(a[i] >> pw) & 255]--] = a[i], --i;
	pw += 8;
	memset(cnt, 0, sizeof(cnt));
	for (i = 1; i <= n - 3; i += 4)
		++cnt[(b[i] >> pw) & 255], ++cnt[(b[i + 1] >> pw) & 255], ++cnt[(b[i + 2] >> pw) & 255], ++cnt[(b[i + 3] >> pw) & 255];
	while (i <= n)
		++cnt[(b[i++] >> pw) & 255];
	for (i = 1; i < 256 - 3; i += 4)
		cnt[i + 3] += cnt[i + 2] += cnt[i + 1] += cnt[i] += cnt[i - 1];
	while (i < 256)
		cnt[i] += cnt[i - 1], ++i;
	for (i = n; i >= 1 + 3; i -= 4)
		a[cnt[(b[i] >> pw) & 255]--] = b[i], a[cnt[(b[i - 1] >> pw) & 255]--] = b[i - 1],
		a[cnt[(b[i - 2] >> pw) & 255]--] = b[i - 2], a[cnt[(b[i - 3] >> pw) & 255]--] = b[i - 3];
	while (i >= 1)
		a[cnt[(b[i] >> pw) & 255]--] = b[i], --i;
	for(int i=0; i<n; ++i) a[i]=a[i+1];
	//memcpy(a,a+1,n*4+4);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1913.763 ms762 MB + 996 KBAcceptedScore: 100


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