fork download
  1. #include <iostream>
  2. using namespace std;
  3. void inp_mas(int m[][100000],int &N)
  4. {
  5. cin>>N;
  6. for(int i=1; i<=N; i++)
  7. for(int j=0; j<2; j++)
  8. cin>>m[j][i];
  9. }
  10. void quicksort(int m[][100000],int left,int right){
  11. int i,j;
  12. i=left;
  13. j=right;
  14. int etalon=m[1][(left+right)/2];
  15. if (m[1][left]>etalon){
  16. swap(m[1][left],m[1][(left+right)/2]);
  17. swap(m[0][left],m[0][(left+right)/2]);
  18. }
  19. if (etalon>m[1][right]){
  20. swap(m[1][(left+right)/2],m[1][right]);
  21. swap(m[0][(left+right)/2],m[0][right]);
  22. }
  23. if (m[1][left]>etalon){
  24. swap(m[1][left],m[1][(left+right)/2]);
  25. swap(m[0][left],m[0][(left+right)/2]);
  26. }
  27. while (i<j){
  28. while(m[1][i]<etalon)
  29. i++;
  30. while(m[1][j]>etalon)
  31. j--;
  32. if (i<=j){
  33. swap(m[1][i],m[1][j]);
  34. swap(m[0][i],m[0][j]);
  35. i++;
  36. j--;
  37. }
  38.  
  39. }
  40. if (left<j)
  41. quicksort(m,left,j);
  42. if (i<right)
  43. quicksort(m,i,right);
  44. }
  45. void out_mas(int m[][100000],int N)
  46. {
  47. for(int i=1; i<=N; i++)
  48. {
  49. cout<<m[0][i]<<" ";
  50. }
  51. }
  52. int m[2][100000];
  53. int main()
  54. {
  55. ios_base::sync_with_stdio(0);
  56. cin.tie(0);
  57. cout.tie(0);
  58. int N;
  59. inp_mas(m,N);
  60. quicksort(m,1,N);
  61. out_mas(m,N);
  62. return 0;
  63. }
Success #stdin #stdout 0.01s 5532KB
stdin
3
3 6
1 12
2 4
stdout
2 3 1