fork download
  1. program formula1;
  2. type elenco = array[1..200000] of qword;
  3. var N,Q,i,j :qword;
  4. a, b, c :array[1..2000] of qword;
  5. p, t, valore, id : elenco;
  6.  
  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 ordinamento (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 ordinamento(estremoi,sup,v,ordinato);
  67. if (inf<estremos) then ordinamento(inf,estremos,v,ordinato);
  68. end;
  69. procedure controlla (var v: elenco; var u : elenco);
  70. var h, w, x, ricorda : qword;
  71. temp : elenco;
  72. begin
  73. h:=1; w:=1;
  74. while (h<=N) do
  75. begin
  76. if v[h]=v[h+1] then
  77. begin
  78. temp[w]:=u[h]; writeln (h);
  79. w:=w+1;
  80. end;
  81. h:=h+1;
  82. end;
  83.  
  84. for h:=1 to w do writeln(temp[w]); writeln;
  85. ricorda:= h-1; writeln('ricorda ',ricorda,' w ',w);
  86. ordinamento(1,w,temp,true);
  87. x:=1;
  88. for h:=ricorda-w+1 to ricorda do begin u[h]:=temp[x]; x:=x+1;end;
  89. end;
  90.  
  91. begin
  92. (*assign(input, 'input.txt'); reset(input);
  93.   assign(output, 'output.txt'); rewrite(output);*)
  94. readln(N);
  95. for i:=1 to N do begin readln(a[i],b[i],c[i]); id[i]:=i; end;
  96. readln(Q);
  97. for i:=1 to Q do
  98. begin
  99. readln (p[i],t[i]);
  100. for j:=1 to N do valore[j]:=calcolavalore(a[j],b[j],c[j],t[i]);
  101. ordinamento(1,N,valore, id, true);
  102. for j:=1 to N do writeln (id[j]); writeln;
  103. controlla (valore, id);
  104. for j:=1 to N do writeln (id[j]); writeln;
  105. writeln(id[p[i]]);
  106. for j:=1 to N do begin valore[j]:=0; id[j]:=j; end;
  107. end;
  108.  
  109. end.
Success #stdin #stdout 0s 5308KB
stdin
5
2 4 6
3 3 8
4 0 5
1 4 1
7 7 6
1
4 0

stdout
2
5
1
3
4

2
0
0

ricorda  1  w  2
5
5
1
3
4

3