[Test3.3-T3] Sorting (卡常)
Posted heanda
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Test3.3-T3] Sorting (卡常)相关的知识,希望对你有一定的参考价值。
Description:
排序一组1e8的数列并输出
Solution:
数列大小是32为的无符号整形
拆2的8次方基数排序即可
Code:
%:pragma GCC optimize("Ofast,inline,unroll-loops")
%:pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define R register
#define I inline
using namespace std;
template<class T>
I void rea(T &x)
{
char ch=getchar();int f(0);x = 0;
while(!isdigit(ch)) {f|=ch=='-';ch=getchar();}
while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
x = f?-x:x;
}
const int N = 100000005;
unsigned int n, seed, a[N], b[N], bucket[256];
I unsigned int Rand()
{
seed^=seed<<5, seed^=seed>>7, seed^=seed<<15;
return seed;
}
I unsigned int get(unsigned int x, unsigned int d)
{
return ((x>>8*(d-1))&255);
}
I void sorting()
{
unsigned int *x(a), *y(b);
for(R int d = 1; d <= 4; ++d)
{
for(R int i = 0; i < 256; ++i) bucket[i] = 0;
for(R int i = 1; i <= n; ++i) bucket[get(x[i], d)]++;
for(R int i = 1; i < 256; ++i) bucket[i] = bucket[i-1]+bucket[i];
for(R int i = n; i >= 1; --i) y[bucket[get(x[i], d)]--] = x[i];
swap(x, y);
}
}
int main()
{
freopen("sorting.in","r",stdin);
freopen("sorting.out","w",stdout);
rea(n), rea(seed);
for(R int i = 1; i <= n; ++i) a[i] = Rand();
sorting();
unsigned int res = 0;
for(R int i = 1; i <= n; ++i) res ^= a[i]+Rand();
cout<<res<<endl;
return 0;
}
以上是关于[Test3.3-T3] Sorting (卡常)的主要内容,如果未能解决你的问题,请参考以下文章