Pagini recente » Cod sursa (job #1098075) | Cod sursa (job #1268201) | Cod sursa (job #1324778) | Cod sursa (job #2401065) | Cod sursa (job #2375074)
#include<bits/stdc++.h>
using namespace std;
ifstream f("radixsort.in");
class OutParser {
private:
FILE *fout;
char *buff;
int sp;
void write_ch(char ch) {
if (sp == 50000) {
fwrite(buff, 1, 50000, fout);
sp = 0;
buff[sp++] = ch;
} else {
buff[sp++] = ch;
}
}
public:
OutParser(const char* name) {
fout = fopen(name, "w");
buff = new char[50000]();
sp = 0;
}
~OutParser() {
fwrite(buff, 1, sp, fout);
fclose(fout);
}
OutParser& operator << (int vu32) {
if (vu32 <= 9) {
write_ch(vu32 + '0');
} else {
(*this) << (vu32 / 10);
write_ch(vu32 % 10 + '0');
}
return *this;
}
OutParser& operator << (long long vu64) {
if (vu64 <= 9) {
write_ch(vu64 + '0');
} else {
(*this) << (vu64 / 10);
write_ch(vu64 % 10 + '0');
}
return *this;
}
OutParser& operator << (char ch) {
write_ch(ch);
return *this;
}
OutParser& operator << (const char *ch) {
while (*ch) {
write_ch(*ch);
++ch;
}
return *this;
}
}g("radixsort.out");
int n, a, b, c;
int v[10000002], v2[10000002];
int sm[260];
int main()
{
f >> n >> a >> b >> c;
v[1] = b;
for(int i = 2; i <= n; ++i)
{
long long z = (1LL * a * v[i-1] + b) % c;
v[i] = z;
}
int nrb = (1<<8) - 1;
for(int i = 0; i <= 3; ++i)
{
memset(sm, 0, sizeof(sm));
for(int j = 1; j <= n; ++j)
{
int xx = (v[j] & nrb);
xx >>= (8 * i);
sm[xx + 1]++;
}
for(int j = 1; j <= 255; ++j)
sm[j] += sm[j-1];
int pz = 0;
for(int j = 1; j <= n; ++j)
{
int xx = (v[j] & nrb);
xx >>= (8 * i);
v2[++sm[xx]] = v[j];
}
memcpy(v, v2, sizeof(v2));
nrb <<= 8;
}
for(int j = 1; j <= n; j += 10)
g << v[j] << " ";
return 0;
}