提交记录 16374


用户 题目 状态 得分 用时 内存 语言 代码长度
imalyd wc2017b1. 【WC2017】挑战-任务1 Accepted 100 2.203 s 1562524 KB C++ 2.92 KB
提交时间 评测时间
2021-07-22 15:00:43 2021-07-22 15:00:47
#include <cstddef>
namespace ya
{
	//template <typename ValType>
	//void fill(ValType *Begin, ValType *End, ValType Val);
	//Fill [Begin, End) with Val.
	template <typename ValType>
	void fill(ValType *Begin, ValType *End, ValType Val)
	{
		for(; Begin != End; ) (*(Begin++)) = Val;
		//std::size_t n(End - Begin);
		//while(n--) (*(Begin++)) = Val;
	}

	
	//template <typename PtrType, typename ValType, typename SizeType>
	//void memset(PtrType Dest, ValType Val, SizeType Size)
	//Fill [Dest, Dest + Size) with (unsigned char)Val.
	//It only works On 64-bit Architecture
	template <typename PtrType, typename ValType, typename SizeType>
	void memset(PtrType Dest, ValType Val, SizeType Size)
	{
		union CharPointerConverter64{
			PtrType PtrPointer;
			unsigned char *CharPointer;
			unsigned long long *LLPointer;
			unsigned long long Number;
		};
		const unsigned char ValChar(Val);
		CharPointerConverter64 Begin, End, Margin;
		Begin.PtrPointer = Dest;
		Margin.Number = Begin.Number + ((unsigned long long)Size & 7ull);
		End.CharPointer = Begin.CharPointer + Size;

		fill(Begin.CharPointer, Margin.CharPointer, ValChar);

		unsigned long long Blk(ValChar);
		Blk |= (Blk << 8);
		Blk |= (Blk << 16);
		Blk |= (Blk << 32);
		fill(Margin.LLPointer, End.LLPointer, Blk);

		/*
		for (char *DestEnd(Dest + Size); Dest != DestEnd;)
			(*(Dest++)) = ValChar;*/
	}
};

#include<cstddef>
namespace ya
{
	#define YA_RADIX_SORT_BASE 256
	#define YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,OP,CntArr) \
	i=Begin2;\
	for(k=0;k!=YA_RADIX_SORT_BASE;++k)\
		La[k]=(i+=CntArr[k]);\
	i=End;\
	do{\
		--i;\
		(*(--La[OP(*i)]))=(*i);\
	}while(i!=Begin);
	void radix_sort(unsigned int *Begin,unsigned int *End){
		size_t N(End-Begin),k;
		unsigned int Begin2[N],*End2(Begin2+N),*La[YA_RADIX_SORT_BASE],*i;
		size_t Cnt1[YA_RADIX_SORT_BASE];memset(Cnt1,0,YA_RADIX_SORT_BASE*sizeof(size_t));
		size_t Cnt2[YA_RADIX_SORT_BASE];memset(Cnt2,0,YA_RADIX_SORT_BASE*sizeof(size_t));
		size_t Cnt3[YA_RADIX_SORT_BASE];memset(Cnt3,0,YA_RADIX_SORT_BASE*sizeof(size_t));
		size_t Cnt4[YA_RADIX_SORT_BASE];memset(Cnt4,0,YA_RADIX_SORT_BASE*sizeof(size_t));
		#define YA_RADIX_SORT_UNSIGNED_INT_OP1(x) ((x)&255u)
		#define YA_RADIX_SORT_UNSIGNED_INT_OP2(x) ((x)>>8&255u)
		#define YA_RADIX_SORT_UNSIGNED_INT_OP3(x) ((x)>>16&255u)
		#define YA_RADIX_SORT_UNSIGNED_INT_OP4(x) ((x)>>24)
		for(i=Begin;i!=End;++i){
			++Cnt1[YA_RADIX_SORT_UNSIGNED_INT_OP1(*i)];
			++Cnt2[YA_RADIX_SORT_UNSIGNED_INT_OP2(*i)];
			++Cnt3[YA_RADIX_SORT_UNSIGNED_INT_OP3(*i)];
			++Cnt4[YA_RADIX_SORT_UNSIGNED_INT_OP4(*i)];
		}

		YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,YA_RADIX_SORT_UNSIGNED_INT_OP1,Cnt1);
		YA_RADIX_SORT_LOOP(Begin2,End2,Begin,End,YA_RADIX_SORT_UNSIGNED_INT_OP2,Cnt2);
		YA_RADIX_SORT_LOOP(Begin,End,Begin2,End2,YA_RADIX_SORT_UNSIGNED_INT_OP3,Cnt3);
		YA_RADIX_SORT_LOOP(Begin2,End2,Begin,End,YA_RADIX_SORT_UNSIGNED_INT_OP4,Cnt4);
	}
	#undef YA_RADIX_SORT_LOOP
};
void sort(unsigned *a, int n){
	ya::radix_sort(a,a+n);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.006 ms804 KBAcceptedScore: 34

Testcase #21.101 s762 MB + 984 KBAcceptedScore: 33

Testcase #32.203 s1525 MB + 924 KBAcceptedScore: 33


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 06:07:23 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠