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+1);
  30. }
  31.  
  32. for (auto i = 0; i < ops; i++) {
  33. int type, x, y;
  34. cin >> type;
  35. printf("Current type: %d\n", type);
  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. printf("Removing ball %d in box %d\n", val, y);
  43. }
  44. } else if (type == 2) {
  45. cin >> x;
  46. int ball = ballNum+1;
  47. ballNum++;
  48. boxes[x].push_back(ball);
  49. printf("Adding new ball %d in box %d\n", ball, x);
  50. } else {
  51. cin >> x;
  52. printf("Checking for ball %d\n", x);
  53. for (auto const& dataPair : boxes) {
  54. for (auto j=0; j < dataPair.second.size(); j++) {
  55. printf("Op3, Checking if ball %d is in box %d\n", x, j);
  56. if (dataPair.second[j] == x) {
  57. cout << j+1 << endl;
  58. printf("Ball %d in box %d\n", x, j+1);
  59. }
  60. }
  61. }
  62. }
  63.  
  64.  
  65. }
  66. }
  67.  
  68.  
  69. int32_t main()
  70. {
  71. ios_base::sync_with_stdio(false);
  72. cin.tie(NULL);
  73. solve();
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 5548KB
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
1
Current type: 3
Checking for ball 5
Op3, Checking if ball 5 is in box 0
Op3, Checking if ball 5 is in box 0
Op3, Checking if ball 5 is in box 0
Op3, Checking if ball 5 is in box 0
Op3, Checking if ball 5 is in box 0
Ball 5 in box 1
Current type: 1
Removing ball 5 in box 4
Current type: 2
Adding new ball 11 in box 1
Current type: 2
Adding new ball 12 in box 4
Current type: 3
Checking for ball 7
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 1
Op3, Checking if ball 7 is in box 2
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 0
Current type: 1
Removing ball 2 in box 1
Removing ball 11 in box 1
Current type: 3
Checking for ball 4
Op3, Checking if ball 4 is in box 0
Op3, Checking if ball 4 is in box 0
Op3, Checking if ball 4 is in box 0
Op3, Checking if ball 4 is in box 0
Ball 4 in box 1
Op3, Checking if ball 4 is in box 1
Op3, Checking if ball 4 is in box 2
Op3, Checking if ball 4 is in box 0
Current type: 1
Removing ball 12 in box 4
Current type: 3
Checking for ball 7
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 1
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 0
Op3, Checking if ball 7 is in box 1
Op3, Checking if ball 7 is in box 2
Current type: 3
Checking for ball 6
Op3, Checking if ball 6 is in box 0
Op3, Checking if ball 6 is in box 0
Op3, Checking if ball 6 is in box 1
Op3, Checking if ball 6 is in box 0
Op3, Checking if ball 6 is in box 0
Op3, Checking if ball 6 is in box 1
Op3, Checking if ball 6 is in box 2