fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define read(type) readInt<type>() // Fast read
  4. #define ll long long
  5. #define nL "\n"
  6. #define pb push_back
  7. #define mk make_pair
  8. #define pii pair<int, int>
  9. #define a first
  10. #define b second
  11. #define vi vector<int>
  12. #define all(x) (x).begin(), (x).end()
  13. #define umap unordered_map
  14. #define uset unordered_set
  15. #define MOD 1000000007
  16. #define imax INT_MAX
  17. #define imin INT_MIN
  18. #define exp 1e9
  19. #define sz(x) (int((x).size()))
  20.  
  21. void solve() {
  22. int boxNum, ops;
  23. cin >> boxNum >> ops;
  24.  
  25. int ballNum = ops;
  26.  
  27. map<int, vector<int>> boxes;
  28. for (auto i = 0; i < boxNum; i++) {
  29. boxes[i].push_back(i);
  30. }
  31.  
  32. for (auto i = 0; i < ops; i++) {
  33. int type, x, y;
  34. cin >> type;
  35.  
  36. if (type == 1) {
  37. cin >> x >> y;
  38. for (auto j = 0; j < boxes[y].size(); j++) {
  39. int val = boxes[y][j];
  40. boxes[y].erase(boxes[y].begin() + j);
  41. boxes[x].push_back(val);
  42. }
  43. } else if (type == 2) {
  44. cin >> x;
  45. int ball = ballNum+1;
  46. ballNum++;
  47. boxes[x].push_back(ball);
  48. } else {
  49. cin >> x;
  50. for (auto const& dataPair : boxes) {
  51. for (auto j=0; j < dataPair.second.size(); j++) {
  52. if (dataPair.second[j] == x) {cout << j+1 << endl;}
  53. }
  54. }
  55. }
  56.  
  57.  
  58. }
  59. }
  60.  
  61.  
  62. int32_t main()
  63. {
  64. ios_base::sync_with_stdio(false);
  65. cin.tie(NULL);
  66. solve();
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5516KB
stdin
5 10
3 5
1 1 4
2 1
2 4
3 7
1 3 1
3 4
1 1 4
3 7
3 6
stdout
1