DarkArtheme

I1

Feb 12th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.     vector<int> v(n);
  10.     for(auto& x : v){
  11.         cin >> x;
  12.     }
  13.     const int Q = 256;
  14.     const int Blocks = 4;
  15.     vector<queue<int>> queues(Q);
  16.     for(int k = 0; k < Blocks; ++k){
  17.         for(int i = 0; i < n; ++i){
  18.             int num = (v[i] >> k*8) & 255;
  19.             queues[num].push(v[i]);
  20.         }
  21.         vector<int> new_v;
  22.         for(auto& q : queues){
  23.             while(!q.empty()) {
  24.                 new_v.push_back(q.front());
  25.                 q.pop();
  26.             }
  27.         }
  28.         v = new_v;
  29.     }
  30.     for(const auto& x : v){
  31.         cout << x << " ";
  32.     }
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment