Pagini recente » Cod sursa (job #2652309) | Cod sursa (job #571795) | Cod sursa (job #287253) | Cod sursa (job #225159) | Cod sursa (job #2221422)
#include <cstdio>
#define uint32_t size_t
__attribute__((always_inline)) void integer_sort(size_t N, size_t *A, size_t *B)
{
for(size_t shift = 0, *t; shift <= 22; shift += 11, t = A, A = B, B = t)
{
size_t frequence[2048]{};
for(size_t i = N; i;) --i, ++frequence[A[i] >> shift & 2047];
for(size_t i = 2047; i;) --i, frequence[i] += frequence[i + 1];
for(size_t i = N; i;) --i, B[--frequence[A[i] >> shift & 2047]] = A[i];
}
}
__attribute__((always_inline)) size_t get_number()
{
static char inBuffer[0x20000];
static size_t p = 0x1FFFF; size_t number = 0x0;
inBuffer[p] > 0x2F || ++p != 0x20000 || (fread(inBuffer, 0x1, 0x20000, stdin), p = 0x0);
for(; inBuffer[p] > 0x2F;)
{
number = number * 0xA + inBuffer[p] - 0x30;
++p != 0x20000 || (fread(inBuffer, 0x1, 0x20000, stdin), p = 0x0);
}
return number;
}
char outBuffer[0x4C4B40]; size_t p = ~0x0;
__attribute__((always_inline)) void put_number(size_t x)
{
size_t digits = x > 0x3B9AC9FF ? 0xB :
x > 0x5F5E0FF ? 0xA :
x > 0x98967F ? 0x9 :
x > 0xF423F ? 0x8 :
x > 0x1869F ? 0x7 :
x > 0x270F ? 0x6 :
x > 0x3E7 ? 0x5 :
x > 0x63 ? 0x4 :
x > 0x9 ? 0x3 : 0x2;
for(size_t i = digits; --i; x /= 0xA)
{
outBuffer[p + i] = x % 0xA + 0x30;
}
outBuffer[p = p + digits] = 0x20;
}
int main()
{
freopen("algsort.in", "r", stdin);
freopen("algsort.out", "w", stdout);
size_t N, v[0x80000], w[0x80000];
N = get_number();
for(size_t i = N; i;)
{
--i; v[i] = get_number();
}
integer_sort(N, v, w);
for(size_t i = N; i;)
{
--i; put_number(w[i]);
}
fwrite(outBuffer, 0x1, p, stdout);
return 0x0;
}