fork download
  1. program formula1;
  2. type elenco = array[1..200000] of qword;
  3. var N,Q,i,j, pos, ans :qword;
  4. a, b, c :array[1..2000] of qword;
  5. p, t, valore, id : elenco;
  6. diversi : boolean;
  7. function calcolavalore (aa,bb,cc,tt:qword): qword;
  8.  
  9. begin
  10. calcolavalore:=aa*tt*tt+bb*tt+cc;
  11. end;
  12.  
  13. Procedure scambia (var aa,bb: qword);
  14. var x:qword;
  15. begin
  16. x:=aa;
  17. aa:=bb;
  18. bb:=x;
  19. end;
  20. Procedure ordinamento (estremoi,estremos: qword; var v : elenco;var u : elenco; ordinato:boolean);
  21. var inf, sup, medio:qword;
  22. pivot :qword;
  23. begin
  24. inf:=estremoi;
  25. sup:=estremos;
  26. medio:= (estremoi+estremos) div 2;
  27. pivot:=v[medio];
  28. repeat
  29. if (ordinato) then
  30. begin
  31. while (v[inf]>pivot) do inf:=inf+1;
  32. while (v[sup]<pivot) do sup:=sup-1;
  33. end;
  34. if inf<=sup then
  35. begin
  36. scambia(v[inf],v[sup]);
  37. scambia(u[inf],u[sup]);
  38. inf:=inf+1;
  39. sup:=sup-1;
  40. end;
  41. until inf>sup;
  42. if (estremoi<sup) then ordinamento(estremoi,sup,v,u,ordinato);
  43. if (inf<estremos) then ordinamento(inf,estremos,v,u,ordinato);
  44. end;
  45. Procedure ordinamento1 (estremoi,estremos: qword; var v : elenco; ordinato:boolean);
  46. var inf, sup, medio:qword;
  47. pivot :qword;
  48. begin
  49. inf:=estremoi;
  50. sup:=estremos;
  51. medio:= (estremoi+estremos) div 2;
  52. pivot:=v[medio];
  53. repeat
  54. if (ordinato) then
  55. begin
  56. while (v[inf]<pivot) do inf:=inf+1;
  57. while (v[sup]>pivot) do sup:=sup-1;
  58. end;
  59. if inf<=sup then
  60. begin
  61. scambia(v[inf],v[sup]);
  62. inf:=inf+1;
  63. sup:=sup-1;
  64. end;
  65. until inf>sup;
  66. if (estremoi<sup) then ordinamento1(estremoi,sup,v,ordinato);
  67. if (inf<estremos) then ordinamento1(inf,estremos,v,ordinato);
  68. end;
  69. procedure controlla (var v: elenco; var u : elenco);
  70. var h, w,z, x, ricorda, inff,supp : qword;
  71. temp : elenco;
  72. begin
  73. diversi:=false;
  74. h:=1; writeln('vpos ', v[pos]);
  75. for h:=1 to N do writeln(v[h]);
  76. while ((v[h]<>v[pos]) and (h<=N)) do begin writeln(v[h],' ciao '); h:=h+1;end;
  77. inff:=h; writeln('inff ',inff);
  78. w:=0;
  79. while ((v[w]=v[pos]) and (w<=N)) do w:=w+1;
  80. supp:=w; z:=1; writeln(' supp');
  81. if inff=supp then ans:=u[pos]
  82. else
  83. begin
  84. for h:=inff to supp do
  85. begin
  86. temp[z]:=u[h];
  87. z:=z+1;
  88. end;
  89. end;
  90. ordinamento1(1,z-1,temp,true);
  91. for h:=1 to z do writeln(temp[h]);
  92. ans:=temp[pos-inff-1] ;
  93. end;
  94.  
  95. begin
  96. (*assign(input, 'input.txt'); reset(input);
  97.   assign(output, 'output.txt'); rewrite(output); *)
  98. readln(N);
  99. for i:=1 to N do begin readln(a[i],b[i],c[i]); id[i]:=i; end;
  100. readln(Q);
  101. for i:=1 to Q do
  102. begin
  103. readln (p[i],t[i]);
  104. pos:=p[i];
  105. for j:=1 to N do valore[j]:=calcolavalore(a[j],b[j],c[j],t[i]);
  106. ordinamento(1,N,valore, id, true);
  107. controlla (valore, id); end; end.
  108. writeln(ans);
  109. for j:=1 to N do begin valore[j]:=0; id[j]:=j; end;
  110. end;
  111.  
  112. end.
Success #stdin #stdout 0.01s 5324KB
stdin
5
2 4 6
3 3 8
4 0 5
1 4 1
7 7 6
1
4 0
stdout
vpos  5
8
6
6
5
1
1  ciao  
inff  6
 supp
0