Advertisement
MathQ_

Untitled

Dec 8th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 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<int, int>> a;
  56.  
  57.     unions(int _m) {
  58.         m = _m;
  59.         a.resize(m + 1);
  60.     }
  61.  
  62.     void ADD(int s, int e) {
  63.         a[s][e] = 1;
  64.     }
  65.  
  66.     void DELETE(int s, int 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.         vector<int> ans;
  76.         for (auto element : a[s]) {
  77.             if (element.se) {
  78.                 ans.push_back(element.fi);
  79.             }
  80.         }
  81.         if (ans.empty()) {
  82.             cout << -1;
  83.         } else {
  84.             cout << ans;
  85.         }
  86.         cout << endl;
  87.     }
  88.  
  89.     void privet(int e) {
  90.         vector<int> ans;
  91.         for (int i = 0; i < m + 1; ++i) {
  92.             if (a[i][e] != 0) {
  93.                 ans.push_back(i);
  94.             }
  95.         }
  96.         if (ans.empty()) {
  97.             cout << -1;
  98.         } else {
  99.             cout << ans;
  100.         }
  101.         cout << endl;
  102.     }
  103. };
  104.  
  105. int main() {
  106.     fast
  107. //  file_in
  108. //  file_in_out
  109.    
  110.     ll n;
  111.     int m, k;
  112.     cin >> n >> m >> k;
  113.     unions u(m);
  114.     string type;
  115.     int e, s;
  116.     while (k--) {
  117.         cin >> type;
  118.         if (type == "ADD") {
  119.             cin >> e >> s;
  120.             u.ADD(s, e);
  121.         }
  122.         if (type == "DELETE") {
  123.             cin >> e >> s;
  124.             u.DELETE(s, e);
  125.         }
  126.         if (type == "CLEAR") {
  127.             cin >> s;
  128.             u.CLEAR(s);
  129.         }
  130.         if (type == "LISTSET") {
  131.             cin >> s;
  132.             u.LIST_SET(s);
  133.         }
  134.         if (type == "LISTSETOF") {
  135.             cin >> e;
  136.             u.privet(e);
  137.         }
  138.     }
  139.     return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement