Cod sursa(job #2375021)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 7 martie 2019 21:51:43
Problema Radix Sort Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("radixsort.in");
ofstream g("radixsort.out");
int n, a, b, c;
int v[10000002];
vector<int>v2[260];
int main()
{
    f >> n >> a >> b >> c;
    v[1] = b;
    for(int i = 2; i <= n; ++i)
    {
        long long z = (1LL * a * v[i-1] + b) % c;
        v[i] = z;
    }
    int nrb = (1<<8) - 1;
    for(int i = 0; i <= 3; ++i)
    {
        for(int j = 0; j <= 255; ++j)
            v2[j].clear();
        for(int j = 1; j <= n; ++j)
        {
            int xx = (v[j] & nrb);
            xx >= (8 * i);
            v2[xx].push_back(v[j]);
        }
        int pz = 0;
        for(int j = 0; j <= 255; ++j)
            for(int k = 0; k < v2[j].size(); ++k)
                v[++pz] = v2[j][k];
        nrb <<= 8;
    }
    for(int j = 1; j <= n; j += 10)
        g << v[j] << " ";
    return 0;
}