Advertisement
NHumme

5A

Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 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 < pair < int, bool > > hash_map[1010101];
  16.  
  17. int hash_f(int x) {
  18.     return (x >= 0 ? x : abs(x)) % 1000000;
  19. }
  20.  
  21. int 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].first == x) {
  25.             if (hash_map[hx][i].second)
  26.                 return i;
  27.             return ~i;
  28.         }
  29.     }
  30.     return -1e9;
  31. }
  32.  
  33. void ins(int x) {
  34.     int t = ex(x);
  35.     if (t < 0) {
  36.             int hx = hash_f(x);
  37.         if (t == -1e9) {
  38.             hash_map[hx].push_back(make_pair(x, true));
  39.             return;
  40.         }
  41.         hash_map[hx][~t].second = true;
  42.     }
  43. }
  44.  
  45. void del(int x) {
  46.     int t = ex(x);
  47.     if (t >= 0) {
  48.         int hx = hash_f(x);
  49.         hash_map[hx][t].second = false;
  50.     }
  51. }
  52.  
  53. int main() {
  54.  
  55. #ifdef _DEBUG
  56.     freopen("debug.in", "r", stdin);
  57.     freopen("debug.out", "w", stdout);
  58. #else
  59.     freopen(TASK".in", "r", stdin);
  60.     freopen(TASK".out", "w", stdout);
  61. #endif // _DEBUG
  62.  
  63.     string s;
  64.     int x;
  65.     while (cin >> s) {
  66.         cin >> x;
  67.         switch (s[0]) {
  68.         case 'i':   ins(x); break;
  69.         case 'd':   del(x); break;
  70.         case 'e':   cout << (ex(x) >= 0 ? "true\n" : "false\n");    break;
  71.         }
  72.     }
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement