Cod sursa(job #2852973)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 19 februarie 2022 19:01:04
Problema Radix Sort Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 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];
deque<int>v[256];
void radix() {

    // int bucket = (1<<8)-1;
    for (int i = 0; i < 4; ++i) {
        int mask = 8 * i;
        for (int j = 0; j < n; ++j)
            v[(a[j] >> mask)&bucket].pb(a[j]);
        n = 0;
        for (int j = 0; j < 256; ++j)
            while (!v[j].empty()) {
                a[n++] = v[j].front();
                v[j].pop_front();
            }
    }

}

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;
}