Cod sursa(job #2852984)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 19 februarie 2022 19:05:41
Problema Radix Sort Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define dbg(i) (cout<<#i<<" = "<<(i)<<'\n')

using ll = long long;

const string fn = "radixsort";

ifstream fin(fn + ".in");
ofstream fout(fn + ".out");

const int bucket = 255;

int n;
int a[10000000];

void radix() {

    // int bucket = (1<<8)-1;
    for (int i = 0; i < 4; ++i) {
        int mask = 8 * i;
        vector<int>v[256];
        for (int j = 0; j < n; ++j)
            v[(a[j] >> mask)&bucket].pb(a[j]);
        n = 0;
        for (int j = 0; j < 256; ++j)
            for (int w : v[j])
                a[n++] = w;
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    fin.tie();
    int A, B, C;
    fin >> n;
    fin >> A >> B >> C;
    a[0] = B;
    for (int i = 1; i < n; ++i)
        a[i] = (1LL * A * a[i - 1] + B) % C;
    radix();
    for (int i = 0; i < n; i += 10)
        fout << a[i] << " ";

    fin.close();
    fout.close();
    return 0;
}