记录编号 370056 评测结果 AAAAATTATTT
题目名称 排序测试 最终得分 54
用户昵称 GravatarAntiLeaf 是否通过 未通过
代码语言 C++ 运行时间 6.786 s
提交时间 2017-02-12 18:48:31 内存使用 48.23 MiB
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int _size_=30;
char is[(_size_<<20)+10],os[(_size_<<20)+10],*pi=is,*po=os;
template<class T>inline void readint(T &x){
	x=0;
	while(*pi<'0')pi++;
	while(*pi>='0')x=(x<<1)+(x<<3)+(*pi++^'0');
}
template<class T>inline void writeint(T x){
	static int a[25],i;
	i=(x==0);
	while(x){
		a[++i]=x%10;
		x/=10;
	}
	while(i)*po++=a[i--]^48;
}
const int maxn=2000010;
unsigned n,a[maxn],b[65537]={0},c[maxn];
int main(){
	freopen("sorttest.in","r",stdin);
	freopen("sorttest.out","w",stdout);
	fread(is,sizeof(is),sizeof(char),stdin);
	readint(n);
	for(unsigned i=0u;i<n;i++){
		readint(a[i]);
		b[(a[i]&65535u)+1]++;
	}
	for(unsigned i=2u;i<65536u;i++)b[i]+=b[i-1u];
	for(unsigned i=0u;i<n;i++)c[b[a[i]&65535u]++]=a[i];
	memset(b,0,sizeof(b));
	for(unsigned i=0u;i<n;i++)b[(c[i]>>16u)+1]++;
	for(unsigned i=2u;i<65536u;i++)b[i]+=b[i-1u];
	for(unsigned i=0u;i<n;i++)a[b[c[i]>>16u]++]=c[i];
	for(unsigned i=0u;i<n;i++){
		writeint(a[i]);
		*po++=' ';
	}
	fwrite(os,po-os,sizeof(char),stdout);
	return 0;
}