Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <cmath>
  5. using namespace std;
  6. int i;
  7. vector<vector<long long>> set(1000005, vector<long long>());
  8.  
  9. void ins(long long x)
  10. {
  11. int num = abs(x % 1000003);
  12. for (i = 0; i < set[num].size(); i++)
  13. {
  14. if (set[num][i] == x) {
  15. return;
  16. }
  17. }
  18. set[num].push_back(x);
  19.  
  20. }
  21.  
  22. void del(long long x)
  23. {
  24. int num = abs(x % 1000003);
  25. for (i = 0; i < set[num].size(); i++)
  26. {
  27. if (set[num][i] == x) {
  28. set[num].erase(set[num].begin() + i);
  29. break;
  30. }
  31. }
  32. }
  33.  
  34. bool exi(long long x)
  35. {
  36. int num = abs(x % 1000003);
  37. for (i = 0; i < set[num].size(); i++)
  38. {
  39. if (set[num][i] == x) {
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45.  
  46. int main()
  47. {
  48. ios_base::sync_with_stdio(false);
  49. cin.tie(NULL);
  50. freopen("set.in", "r", stdin);
  51. freopen("set.out", "w", stdout);
  52. string s;
  53. long long x;
  54. while (cin >> s)
  55. {
  56. if (s == "insert") {
  57. cin >> x;
  58. ins(x);
  59. }
  60. else if (s == "delete") {
  61. cin >> x;
  62. del(x);
  63.  
  64. }
  65. else {
  66. cin >> x;
  67. if (exi(x)) cout << "true\n";
  68. else cout << "false\n";
  69. }
  70. /*for (int j = 0; j < set.size(); j++)
  71. {
  72. for (int h = 0; h < set[j].size(); h++)
  73. cout << set[j][h] << " " << j << " " << h << "\n";
  74. }*/
  75. }
  76. return 0;
  77. }
  78. /*
  79. delete 1
  80. delete 2
  81. insert 2
  82. insert 5
  83. insert 1000005
  84. insert 3
  85. exists 2
  86. exists 4
  87. insert 2
  88. delete 2
  89. delete 2
  90. delete 2
  91. exists 2
  92. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement