Advertisement
a53

Multiset_OOP

a53
May 28th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. class Multiset
  2. {
  3. public:
  4. int n,aib[1000001];
  5. Multiset(int n)
  6. {
  7. this->n=n;
  8. for(int i=0;i<=n;++i)
  9. aib[i]=0;
  10. }
  11.  
  12. void Insert(int x)
  13. {
  14. for(int i=x;i<=n;i+=(i&-i))
  15. ++aib[i];
  16. }
  17.  
  18. int Find(int x)
  19. {
  20. int y=0;
  21. for(int k=(1<<19);k>=1;k/=2)
  22. if(y+k<n&&aib[y+k]<x)
  23. x=x-aib[y+k],y+=k;
  24. return y+1;
  25. }
  26.  
  27. void Erase(int x)
  28. {
  29. int y=Find(x);
  30. for(int i=y;i<=n;i+=(i&-i))
  31. --aib[i];
  32. }
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement