fork download
  1. #include<bits/stdc++.h>
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. // Declaring functions
  7. void inizia(int N, int M);
  8. void sposta(int a, int b);
  9. int controlla(int a, int i);
  10. using namespace std;
  11.  
  12. vector<vector<int>>v;
  13.  
  14. void inizia(int N, int M) {
  15. vector<int>v1;
  16. for(int i=0;i<N;i++){
  17. v1.push_back(i);
  18. }
  19. v.push_back(v1);
  20. for(int i=1;i<M;i++){
  21. vector<int>v2;
  22. v.push_back(v2);
  23. }
  24. }
  25.  
  26. void sposta(int a, int b) {
  27. if(v[a].size()>0){
  28. v[b].push_back(v[a].back());
  29. v[a].pop_back();
  30. }
  31. }
  32.  
  33. int controlla(int a, int i) {
  34. if(v[a].size()<=i){
  35. return -1;
  36. }else{
  37. return v[a][i];
  38. }
  39. }
  40.  
  41. int main() {
  42. // Uncomment the following lines if you want to read/write from files
  43. // ifstream cin("input.txt");
  44. // ofstream cout("output.txt");
  45.  
  46. ios::sync_with_stdio(false);
  47.  
  48. int N, M, Q;
  49. cin >> N >> M >> Q;
  50.  
  51. inizia(N, M);
  52.  
  53. for (int i = 0; i < Q; i++) {
  54. char t;
  55. int a, b;
  56. cin >> t >> a >> b;
  57. if (t == 's') {
  58. sposta(a, b);
  59. } else {
  60. cout << controlla(a, b) << '\n';
  61. }
  62. }
  63.  
  64. return 0;
  65. }
  66.  
  67.  
Success #stdin #stdout 0.01s 5288KB
stdin
3 3 2
s 0 1
c 1 0

stdout
2