Pagini recente » Cod sursa (job #1162116) | Cod sursa (job #702354) | Cod sursa (job #463781) | Cod sursa (job #2093787) | Cod sursa (job #3220804)
#include <iostream>
#include <fstream>
#include <stdint.h>
const int64_t WORD_SIZE_LOG_2 = 8;
const int64_t WORD_SIZE = 1 << WORD_SIZE_LOG_2;
const int64_t WORD_COUNT = 4;
const int64_t MAX_N = 10000000;
int64_t vec[MAX_N];
int64_t vec2[MAX_N];
int main() {
std::ifstream fin("radixsort.in");
std::ofstream fout("radixsort.out");
int64_t n, a, b, c;
fin >> n >> a >> b >> c;
vec[0] = b;
for(int64_t i = 1; i != n; ++i)
vec[i] = (a * vec[i - 1] + b) % c;
for(int64_t i = 0; i != WORD_COUNT; ++i) {
int64_t starts[WORD_SIZE];
for(int64_t j = 0; j != WORD_SIZE; ++j)
starts[j] = 0;
for(int64_t j = 0; j != n; ++j) {
int64_t word = (vec[j] >> (WORD_SIZE * i)) & (WORD_SIZE - 1);
if(word != WORD_SIZE - 1)
++starts[word + 1];
}
for(int64_t j = 2; j != WORD_SIZE; ++j)
starts[j] += starts[j - 1];
for(int64_t j = 0; j != n; ++j) {
int64_t word = (vec[j] >> (WORD_SIZE * i)) & (WORD_SIZE - 1);
vec2[starts[word]++] = vec[j];
}
for(int64_t j = 0; j != n; ++j)
vec[j] = vec2[j];
}
for(int64_t i = 0; i < n; i += 10)
fout << vec[i] << ' ';
fin.close();
fout.close();
}