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