rembocoder

Untitled

May 27th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define forn(i, n) for (int i = 0; i < (int)(n); ++i)
  6.  
  7. struct randomSet {
  8. unordered_map<int> m;
  9. vector<int> v;
  10. void add(int x) {
  11. if (m.find(x) != m.end()) {
  12. return;
  13. }
  14. m[x] = v.size();
  15. v.push_back(x);
  16. }
  17. void del(int x) {
  18. if (m.find(x) == m.end()) {
  19. return;
  20. }
  21. int i = m[x];
  22. v[i] = v.back();
  23. v.pop_back();
  24. m[v[i]] = i;
  25. }
  26. int getRand() {
  27. return v[rand() % v.size()];
  28. }
  29. };
  30.  
  31. int main() {
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment