Cod sursa(job #2852943)

Utilizator cristia_razvanCristia Razvan cristia_razvan Data 19 februarie 2022 18:40:41
Problema Radix Sort Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 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[10000005];
deque<int>v[256];
void radix() {
    int mask;
    // int bucket = (1<<8)-1;
    for (int i = 0; i < 4; ++i) {
        mask = 8 * i;
        for (int j = 1; 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() {

    int A, B, C;
    fin >> n;
    fin >> A >> B >> C;
    a[1] = B;
    for (int i = 2; i <= n; ++i)
        a[i] = (1LL * A * a[i - 1] + B) % C;
    radix();
    for (int i = 1; i <= n; i += 10)
        fout << a[i] << ' ';

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