Naxocist

HashingTable

Apr 3rd, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endll '\n'
  3. using namespace std;
  4.  
  5. const int N = 1e6+3;
  6. list<int> a[N];
  7. int input[N];
  8.  
  9. int main() {
  10.    
  11.     int s, n; cin >> s >> n;
  12.  
  13.     for(int i=0; i<n; ++i) cin >> input[i];
  14.     unordered_map<int, list<int>> umap; // <index, value>
  15.  
  16.     while(s/2 < n) s*=2;
  17.  
  18.     for(int i=0; i<n; ++i){
  19.         int r = input[i]%s;
  20.         umap[r].push_back(input[i]);
  21.     }
  22.  
  23.    
  24.     for(int i=0; i<s; ++i){
  25.         if(umap.find(i) != umap.end()) {
  26.             for(auto x : umap[i]) cout << x << ' ';
  27.         }else cout << "empty";
  28.         cout << endll;
  29.     }
  30.    
  31.     return 0;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment