Cod sursa(job #3222674)

Utilizator SSKMFSS KMF SSKMF Data 11 aprilie 2024 11:22:04
Problema Radix Sort Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <fstream>
using namespace std;

ifstream cin ("radixsort.in");
ofstream cout ("radixsort.out");

int sir[10000001] , temporar[10000001];

int main ()
{
    int lungime , factor , termen , mod;
    cin >> lungime >> factor >> termen >> mod;

    sir[1] = termen;
    for (int indice = 2 ; indice <= lungime ; indice++)
        { sir[indice] = ((int64_t)factor * sir[indice - 1] + termen) % mod; }

    for (int bit = 0 ; bit < 32 ; bit += 16)
    {
        int aparitii[65536] = { };
        for (int indice = 1 ; indice <= lungime ; indice++)
            { aparitii[sir[indice] >> bit & 65535]++; }

        int inceput[65536] = { }; inceput[0] = 1;
        for (int indice = 1 ; indice < 65536 ; indice++)
            { inceput[indice] = inceput[indice - 1] + aparitii[indice - 1]; }

        for (int indice = 1 ; indice <= lungime ; indice++)
            { temporar[inceput[sir[indice] >> bit & 65535]++] = sir[indice]; }

        for (int indice = 1 ; indice <= lungime ; indice++)
            { sir[indice] = temporar[indice]; }
    }

    for (int indice = 1 ; indice <= lungime ; indice += 10)
        { cout << sir[indice] << ' '; }

    cout.close(); cin.close();
    return 0;
}