Advertisement
NHumme

KEK

Nov 15th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <string>
  7. #include <set>
  8. #include <stack>
  9. #include <queue>
  10. #include <deque>
  11. using namespace std;
  12.  
  13. #define TASK "set"
  14.  
  15. vector < int > hash_map[1000000];
  16.  
  17. int hash_f(int x) {
  18.     return x % 1000000;
  19. }
  20.  
  21. bool ex(int x) {
  22.     int hx = hash_f(x);
  23.     for (int i = 0; i < hash_map[hx].size(); i++) {
  24.         if (hash_map[hx][i] == x) {
  25.             return true;
  26.         }
  27.     }
  28.     return false;
  29. }
  30.  
  31. void ins(int x) {
  32.     if (!ex(x)) {
  33.         int hx = hash_f(x);
  34.         hash_map[hx].push_back(x);
  35.     }
  36. }
  37.  
  38. void del(int x) {
  39.     if (ex(x)) {
  40.         int hx = hash_f(x);
  41.         for (int i = 0; i < hash_map[hx].size(); i++) {
  42.             if (hash_map[hx][i] == x) {
  43.                 hash_map[hx].erase(hash_map[hx].begin() + i);
  44.                 return;
  45.             }
  46.         }
  47.     }
  48. }
  49.  
  50. int main() {
  51.  
  52. #ifdef _DEBUG
  53.     freopen("debug.in", "r", stdin);
  54.     freopen("debug.out", "w", stdout);
  55. #else
  56.     freopen(TASK".in", "r", stdin);
  57.     freopen(TASK".out", "w", stdout);
  58. #endif // _DEBUG
  59.  
  60.     string s;
  61.     int x;
  62.     while (cin >> s) {
  63.         cin >> x;
  64.         switch (s[0]) {
  65.         case 'i':   ins(x); break; 
  66.         case 'd':   del(x); break;
  67.         case 'e':   cout << (ex(x) ? "true\n" : "false\n"); break;
  68.         }
  69.     }
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement