fork download
  1. program cestini;
  2. { NOTA: si raccomanda di usare questo template anche se non lo si capisce completamente }
  3.  
  4. const
  5. MAX = 100000;
  6.  
  7. var
  8. M, N, Q, T, i, h,test : LongInt;
  9. S, ans : AnsiString;
  10. qtype : Array[0..MAX-1] of Char;
  11. a, b , index : Array[0..MAX-1] of LongInt;
  12.  
  13. v: array of array of longint;
  14.  
  15.  
  16. procedure inizia (N:Longint; M:Longint) ;
  17. var j:longint;
  18. begin
  19. setLength(V, M,0);
  20. setLength(V[0], N);
  21. for j:=0 to N-1 do V[0][j]:= j;
  22. index[0]:=N-1;
  23. for j:=1 to M-1 do index[j]:= 0;
  24. end;
  25. Procedure sposta (a:Longint;b:Longint);
  26. begin
  27. setLength(V[b], index[b]+1);
  28. V[b][index[b]]:=V[a][index[a]];
  29. index[a]:=index[a]-1;
  30. setLength(V[a], index[a]);
  31. writeln(index[a]);
  32. index[b]:=index[b]+1;
  33. writeln(Length(V[a]),' ',Length(V[b]));
  34. end;
  35.  
  36. function controlla (a:Longint;i:Longint) : longint;
  37.  
  38. begin
  39. if index[a]<=i then controlla:=-1
  40. else controlla:=V[a][i];
  41. writeln(controlla) ;
  42.  
  43. end;
  44.  
  45.  
  46. begin
  47. {
  48.   decommenta le due righe seguenti se vuoi leggere/scrivere da file
  49.   assign(input, 'input.txt'); reset(input);
  50.   assign(output, 'output.txt'); rewrite(output);
  51. }
  52.  
  53. ReadLn(N, M, Q);
  54. for i:=0 to Q -1 do
  55. ReadLn(qtype[i], a[i], b[i]);
  56. ans := '';
  57. inizia(N,M);
  58. for i:=0 to Q-1 do
  59. begin
  60. if qtype[i]='s' then sposta(a[i],b[i])
  61. else if qtype[i]='c' then controlla(a[i],b[i]);
  62.  
  63. end;
  64.  
  65. end.
  66.  
Success #stdin #stdout 0s 5312KB
stdin
5 6 7
s 0 1
c 1 0
s 0 2
s 1 2
s 0 2
c 2 2
c 2 1
stdout
3
3 1
4
2
2 1
0
0 2
1
1 3
2
0