Блог пользователя LashaBukhnikashvili

Автор LashaBukhnikashvili, 10 лет назад, По-английски

here is the link of a problem,I wrote O(n log n + m log^3 n) solution,but I have wa16, here is my code.

please help to find my mistake,also I am interested log n and log^2 n solutions.

Any help will be appreciated very much :)

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

for O((n+m) log n) solution see here

  • »
    »
    10 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    could you explain your solution?

    • »
      »
      »
      10 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Sort the array keeping track of indexes so I have A[0] is the index of smallest number and A[n-1] is the index of biggest number

      Now if I want K-th smallest number in range [l,r] the naive way is like the code

      int tmp=0;
      for(int i=0;i<n;i++){
      if(l<=A[i] && A[i]<=r)tmp++;
      if(tmp==k){
      cout<<A[i]<<endl; //output the index
      break;
      }
      }
      

      This has complexity O(n) for each operation

      I use sqrt decompstion to make it faster

      • »
        »
        »
        »
        10 лет назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        Can you please comment your code a bit so that it makes it easier to understand? I have no idea what your pre[][] array does and not able to understand it from the link that you've posted.

      • »
        »
        »
        »
        10 лет назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        it is hard to understand idea from your code, but when you explain I got it,thanks,great idea ;)