Advertisement
Guest User

Untitled

a guest
Mar 11th, 2015
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. vector<pair<int,int>> blocks[num_of_arrays];
  2.  
  3. // ...
  4.  
  5. int number;
  6. cin >> number; // number requested
  7. int f = frequency[number];
  8. pair<int,int> x = {frequency, number};
  9.  
  10. int id = 0; // first array
  11. while (id + 1 < num_of_arrays && blocks[id + 1][0] >= x) // O(sqrt(n))
  12.     ++id;
  13. int pos = 0;
  14. while (pos + 1 < blocks[id].size() && blocks[id][pos + 1] >= x) // O(sqrt(n))
  15.     ++pos;
  16.  
  17. // we found array (id), and position in the array (pos)
  18. // thus can do, for example, insertion:
  19. blocks[id].insert(blocks[id].begin() + pos, x); // size of blocks[id] <= 2 * sqrt(n)
  20.  
  21. // or deletion:
  22. blocks[id].erase(blocks[id].begin() + pos, x); // size of blocks[id] <= 2 * sqrt(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement