Advertisement
Egor_1425

Untitled

Jul 27th, 2024
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int main() {
  7.     ll n;
  8.     int m, k;
  9.     cin >> n >> m >> k;
  10.     map<int, set<ll>> q;
  11.     map<ll, set<int>> w;
  12.     for (int v = 0; v < k; ++v) {
  13.         string a;
  14.         cin >> a;
  15.         if (a == "ADD") {
  16.             ll y;
  17.             int x;
  18.             cin >> y >> x;
  19.             q[x].insert(y);
  20.             w[y].insert(x);
  21.         }
  22.         else if (a == "DELETE") {
  23.             int x;
  24.             ll y;
  25.             cin >> y >> x;
  26.             q[x].erase(q[x].find(y));
  27.             w[y].erase(w[y].find(x));
  28.         }
  29.         else if (a == "CLEAR") {
  30.             int x;
  31.             cin >> x;
  32.             for (auto i = q[x].begin(); i != q[x].end(); ++i)
  33.                 w[*i].erase(w[*i].find(x));
  34.             q[x].clear();
  35.         }
  36.         else if (a == "LISTSET") {
  37.             int x;
  38.             cin >> x;
  39.             if (q[x].size() == 0)
  40.                 cout << -1 << '\n';
  41.             else {
  42.                 for (auto i = q[x].begin(); i != q[x].end(); ++i)
  43.                     cout << *i << ' ';
  44.                 cout << '\n';
  45.             }
  46.         }
  47.         else if (a == "LISTSETSOF") {
  48.             ll x;
  49.             cin >> x;
  50.             if (w[x].size() == 0)
  51.                 cout << -1 << '\n';
  52.             else {
  53.                 for (auto i = w[x].begin(); i != w[x].end(); ++i)
  54.                     cout << *i << ' ';
  55.                 cout << '\n';
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement