Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <vector>
- using std::cin;
- using std::cout;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- using Ll = long long;
- const int k8 = 8;
- const int k256 = 256;
- int len;
- vector<Ll> ar;
- vector<int> less_than;
- vector<Ll> hlp;
- Ll Byte(Ll num, int par) {
- Ll kk = ((1LL << k8) - 1) * (1LL << (k8 * par));
- Ll res = num & kk;
- Ll div = (1LL << (k8 * par));
- res /= div;
- return res;
- }
- void LSD(int par) {
- // cout << "GO\n";
- // cout << "par = " << par << "\n";
- less_than.assign(k256, 0);
- for (int id = 0; id < len; ++id) {
- Ll bt = Byte(ar[id], par);
- // cout << "id = " << id << "\n";
- // cout << "ar[id] = " << ar[id] << "\n";
- // cout << "bt = " << bt << "\n";
- less_than[bt]++;
- }
- // cout << "A\n";
- int cnt = 0;
- for (int id = 0; id < k256; ++id) {
- int point = less_than[id];
- less_than[id] = cnt;
- cnt += point;
- }
- // cout << "B\n";
- for (int id = 0; id < len; ++id) {
- Ll bt = Byte(ar[id], par);
- hlp[less_than[bt]] = ar[id];
- less_than[bt]++;
- }
- ar = hlp;
- }
- int main() {
- std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);
- cin >> len;
- ar.resize(len);
- hlp.resize(len);
- for (Ll& el : ar) {
- cin >> el;
- }
- for (int par = 0; par < k8; ++par) {
- LSD(par);
- }
- for (Ll el : ar) {
- cout << el << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement