-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Problem proposal] Integer Sort #1280
Comments
For generic comparison-based sort, we also already have Sort Points by Argument, but the constraints seem not large enough for it to be a nice sorting benchmark 🤔 |
I also wonder whether it's best to just give one array, or a lot of arrays and guarantee their total size is up to |
In my benchmarks, a small constant radix sort can sort a random array of length Theoretically, The complexity of reading Code (the radix sort implementation is adapted from platelet's code): #include <algorithm>
#include <boost/timer/timer.hpp> // for accurate cpu time
#include <iostream>
#include "fastio.hpp" // library checker's
constexpr int N = 10'000'000;
unsigned int a[N], b[N];
void sort(unsigned int* a, int __n) {
unsigned int n = __n;
unsigned int buc[4][256] = {};
for (unsigned int i = 0; i < n; i++) {
buc[0][a[i] & 255]++;
buc[1][a[i] >> 8 & 255]++;
buc[2][a[i] >> 16 & 255]++;
buc[3][a[i] >> 24]++;
}
for (unsigned int k = 0; k < 4; k++) {
unsigned int offset = 0;
for (unsigned int i = 0; i < 256; i++)
std::swap(buc[k][i], offset), offset += buc[k][i];
}
for (unsigned int i = 0; i < n; i++) b[buc[0][a[i] & 255]++] = a[i];
for (unsigned int i = 0; i < n; i++) a[buc[1][b[i] >> 8 & 255]++] = b[i];
for (unsigned int i = 0; i < n; i++) b[buc[2][a[i] >> 16 & 255]++] = a[i];
for (unsigned int i = 0; i < n; i++) a[buc[3][b[i] >> 24 & 255]++] = b[i];
}
int main()
{
library_checker::Scanner sc(stdin);
library_checker::Printer pr(stdout);
int n = 0;
sc.read(n);
for (int i = 0; i < n; i++) sc.read(a[i]);
{
boost::timer::auto_cpu_timer t(std::cerr);
sort(a, n);
}
for (int i = 0; i < n; i++) {
if (i) pr.write(' ');
pr.write(a[i]);
}
pr.writeln();
return 0;
} result:
|
Good point. Might be worthwhile to give input as a generator, similar to KSMALL? But then it might be difficult to add special cases, like breaking certain quicksorts, or giving already sorted array... |
Regarding output, if necessary, it is possible to output an appropriate hash. As an alternative, we can offer |
Problem name: Integer Sort
(Optional) Problem ID: sort_integers
Problem
Given$n$ integers $A_1,\dots,A_n$ , sort them.
Constraint
Solution / Reference
(Optional) Input
(Optional) Output
where$B_1 \leq \dots \leq B_n$ .
(Optional) Note / Disucussion
The text was updated successfully, but these errors were encountered: