Advertisement
MathQ_

Untitled

Dec 9th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  2. #pragma GCC optimize 03
  3. #pragma GCC optimize("unroll-loops")
  4.  
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <iterator>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <vector>
  11. #include <deque>
  12. #include <queue>
  13. #include <set>
  14. #include <map>
  15. #include <stack>
  16. #include <string>
  17. #include <random>
  18. #include <numeric>
  19. #include <unordered_set>
  20.  
  21. typedef long long ll;
  22. typedef long double lb;
  23.  
  24. #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  25. #define file_in freopen("input.txt", "r", stdin);
  26. #define file_in_out freopen("knapsack.in", "r", stdin); freopen("knapsack.out", "w", stdout);
  27. #define mp make_pair
  28. #define all(x) (x).begin(), (x).end()
  29. #define fi first
  30. #define se second
  31.  
  32. using namespace std;
  33.  
  34. template<typename T>
  35. istream& operator>>(istream &in, vector<T> &v) {
  36.     for (auto &it : v) {
  37.         in >> it;
  38.     }
  39.     return in;
  40. }
  41.  
  42. template<typename T>
  43. ostream& operator<<(ostream &out, vector<T> &v) {
  44.     if (!v.empty()) {
  45.         out << v.front();
  46.         for (int i = 1; i < v.size(); ++i) {
  47.             out << " " << v[i];
  48.         }
  49.     }
  50.     return out;
  51. }
  52.  
  53. struct unions {
  54.     int m;
  55.     vector<map<ll, int>> a;
  56.  
  57.     unions(int _m) {
  58.         m = _m;
  59.         a.resize(m + 1);
  60.     }
  61.  
  62.     void ADD(int s, ll e) {
  63.         a[s][e] = 1;
  64.     }
  65.  
  66.     void DELETE(int s, ll e) {
  67.         a[s][e] = 0;
  68.     }
  69.  
  70.     void CLEAR(int s) {
  71.         a[s].clear();
  72.     }
  73.  
  74.     void LIST_SET(int s) {
  75.         bool ans = false;
  76.         for (auto element : a[s]) {
  77.             if (element.se) {
  78.                 ans = true;
  79.                 cout << element.fi << " ";
  80.             }
  81.         }
  82.         if (!ans) {
  83.             cout << -1;
  84.         }
  85.         cout << "\n";
  86.     }
  87.  
  88.     void LIST_SETS_OF(int e) {
  89.         bool ans = false;
  90.         for (int i = 0; i < m + 1; ++i) {
  91.             if (a[i][e] != 0) {
  92.                 ans = true;
  93.                 cout << i << " ";  
  94.             }
  95.         }
  96.         if (!ans) {
  97.             cout << -1;
  98.         }
  99.         cout << "\n";
  100.     }
  101. };
  102.  
  103. int main() {
  104.     fast
  105. //  file_in
  106. //  file_in_out
  107.    
  108.     ll n;
  109.     int m, k;
  110.     cin >> n >> m >> k;
  111.     unions u(m);
  112.     string type;
  113.     ll e, s;
  114.     while (k--) {
  115.         cin >> type;
  116.         if (type == "ADD") {
  117.             cin >> e >> s;
  118.             u.ADD(s, e);
  119.         }
  120.         if (type == "DELETE") {
  121.             cin >> e >> s;
  122.             u.DELETE(s, e);
  123.         }
  124.         if (type == "CLEAR") {
  125.             cin >> s;
  126.             u.CLEAR(s);
  127.         }
  128.         if (type == "LISTSET") {
  129.             cin >> s;
  130.             u.LIST_SET(s);
  131.         }
  132.         if (type == "LISTSETSOF") {
  133.             cin >> e;
  134.             u.LIST_SETS_OF(e);
  135.         }
  136.     }
  137.     return 0;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement