Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include".\template\headers.hpp"
- // #define MULTI_TASKCASE
- using namespace abb;
- using namespace output;
- using namespace rit;
- using namespace wit;
- inline void init() {
- }
- constexpr int n = 9e5;
- constexpr int maxexp = 9;
- void radix_sort(A<int, n>& arr, int exp) {
- const int base = 1 << exp;
- static A < A<int, n>, (1 << maxexp) > bucket;
- static A < int, (1 << maxexp) > cnt;
- auto find_maxt = [&arr, exp]() {
- int maxn = *max_element(arr.begin(), arr.end()), cnt = 0;
- while (maxn) cnt++, maxn >>= exp;
- return cnt;
- };
- auto maxt = find_maxt();
- for (int k = 0; k < maxt; k++) {
- fill(cnt.begin(), cnt.end(), 0);
- for (const auto& i : arr) {
- int id = (i >> (k * exp)) & (base - 1);
- bucket[id][cnt[id]++] = i;
- }
- auto ptr = arr.begin();
- for (int i = 0; i < base; i++)
- for (int j = 0; j < cnt[i]; j++)
- *ptr++ = bucket[i][j];
- }
- }
- inline void solve() {
- static A<int, n> v;
- A<A<double, 20>, maxexp> arr;
- for (int j = 0; j != maxexp; j++) {
- fstream filein("in.txt", ios::in);
- cin.rdbuf(filein.rdbuf());
- for (auto& k : arr[j]) {
- cout << "poop" << ' ';
- for (auto& i : v)
- cin >> i;
- clock_t before = clock();
- radix_sort(v, j + 1);
- clock_t after = clock();
- k = double(after - before) / CLOCKS_PER_SEC * 1000;
- }
- filein.close();
- cout << endl << flush;
- }
- fstream fileout("out.txt", ios::out);
- cout.rdbuf(fileout.rdbuf());
- for (int i = 0; i != 20; i++) {
- for (int j = 0; j < maxexp - 1; j++)
- cout << arr[j][i] << '\t';
- cout << arr[maxexp - 1][i] << endl;
- }
- fileout.close();
- }
- main() {
- ios::sync_with_stdio(false);
- init();
- int t = 1;
- #ifdef MULTI_TASKCASE
- cin >> t; cin.ignore();
- #endif
- while (t--) solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment