Pagini recente » Monitorul de evaluare | Cod sursa (job #195461) | Cod sursa (job #146352) | Cod sursa (job #21442) | Cod sursa (job #2618839)
#include <cstdio>
#include <vector>
#include <fstream>
using namespace std;
const int NMAX = 10000505;
const int LMAX = (1 << 8);
int N, A, B, C;
int nums[NMAX];
inline int getValue(int& value, int from, int toExclusive) {
long long temp = ((1LL << toExclusive) - 1) & value;
return temp >> from;
}
int main() {
ifstream in("radixsort.in");
ofstream out("radixsort.out");
in >> N >> A >> B >> C;
nums[1] = B;
for (int idx = 2; idx <= N; idx++) {
nums[idx] = (1LL * nums[idx - 1] * A + B) % C;
}
for (int byteIdx = 0; byteIdx < 4; byteIdx++) {
vector<vector<int>> orderedByByte(LMAX, vector<int>());
vector<int> cntByte(LMAX, 0);
for (int idx = 1; idx <= N; idx++) {
int byteValue = getValue(nums[idx], byteIdx << 3, (byteIdx + 1) << 3);
cntByte[byteValue]++;
}
for (int byteValue = 0; byteValue < LMAX; byteValue++) {
orderedByByte.reserve(cntByte[byteValue]);
}
for (int idx = 1; idx <= N; idx++) {
int byteValue = getValue(nums[idx], byteIdx << 3, (byteIdx + 1) << 3);
orderedByByte[byteValue].push_back(nums[idx]);
}
int nextPos = 1;
for (int value = 0; value < LMAX; value++) {
for (auto& entry : orderedByByte[value]) {
nums[nextPos++] = entry;
}
}
}
for (int idx = 1; idx <= N; idx += 10) {
out << nums[idx] << " ";
}
out << "\n";
return 0;
}