Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. const int N = 2e5 + 228;
  5. const int M = 2e5;
  6. struct hashset {
  7. vector<int> a[N];
  8.  
  9. int get_hash(int x) {
  10. x = abs(x);
  11. return x % M;
  12. }
  13.  
  14. void insert(int x) {
  15. int hash = get_hash(x);
  16. if (che(x)) return;
  17. a[hash].push_back(x);
  18. }
  19. void del(int x) {
  20. if (!che(x)) return;
  21. int hash = get_hash(x);
  22. for (int i = 0; i < a[hash].size(); ++ i) {
  23. if (x == a[hash][i]) {
  24. swap(a[hash][i], a[hash][a[hash].size() - 1]);
  25. a[hash].pop_back();
  26. return;
  27. }
  28. }
  29. }
  30. bool che(int x){
  31. int hash = get_hash(x);
  32. for (int i : a[hash]) {
  33. if (i == x) return true;
  34. }
  35. return false;
  36. }
  37. };
  38.  
  39. int32_t main() {
  40. ios_base::sync_with_stdio(0);
  41. freopen("set.in", "r", stdin);
  42. freopen("set.out", "w", stdout);
  43. hashset set;
  44. string s;
  45. while (cin >> s) {
  46. if ( s == "insert") {
  47. int q;
  48. cin >> q;
  49. set.insert(q);
  50. } else if (s == "delete") {
  51. int x;
  52. cin >> x;
  53. set.del(x);
  54. } else {
  55. int x;
  56. cin >> x;
  57. bool q = set.che(x);
  58. if (q)
  59. cout << "true" << endl;
  60. else
  61. cout << "false" << endl;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement