a_gt3_rs's blog

By a_gt3_rs, history, 2 months ago, In English

Is this problem doable with less than $$$O(n\sqrt{n}log(log(n)))$$$ time?

Given an array $$$p$$$, assuming $$$p_i=O(n)$$$. The array is cut to $$$O(\sqrt{n})$$$ blocks.

There is only one kind of query:

$$$1\ i\ j\ k$$$: Count the numbers from block $$$i$$$ to block $$$j$$$ such that $$$p_k$$$ is a multiple of (the query must be done in $$$O(1)$$$).

Any help is appreciated.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Just don't split it into blocks, you can do it in O(nlog^2) with offline queries

  • »
    »
    2 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Is the queries guranteed to be $$$O(1)$$$? Because i need to do $$$O(n\sqrt{n})$$$ of them.

    • »
      »
      »
      2 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Is it online? if not, why?

      • »
        »
        »
        »
        2 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It doesn't need to be online

        • »
          »
          »
          »
          »
          2 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Then you can just not split it into blocks and process it in $$$\mathcal{O}(n \times log^2(n))$$$

          • »
            »
            »
            »
            »
            »
            2 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Can you give more details about the solution

            • »
              »
              »
              »
              »
              »
              »
              2 months ago, # ^ |
              Rev. 2   Vote: I like it 0 Vote: I do not like it

              I'll assume we're working within a reasonable limits here, where $$$1 <= n, a_i <= 2 \times 10^5$$$

              We can store all of the positions of an element in a vector/array, let's call the array $$$pos[k]$$$. We can now find the occurrences of number $$$k$$$ in $$$log(n)$$$ by binary searching through the array.

              As we're processing the queries offline, first we need to store the queries in an array, let's call $$$queries[k]$$$ the queries where we need to find the divisors of $$$k$$$. We can now simply iterate from $$$1$$$ to $$$max(a)$$$ and iterate through the multiples of it, in which we'll iterate through the queries and answer them.

              Total time complexity: $$$\mathcal{O}(n \times log^2(n))$$$ because we'll be iterating through $$$n + n / 1 + n / 2 + ... + n / n \approx n \times log(n)$$$, and it takes $$$log(n)$$$ to answer each queries.

              • »
                »
                »
                »
                »
                »
                »
                »
                2 months ago, # ^ |
                  Vote: I like it 0 Vote: I do not like it

                Now remove $$$O(n)$$$ part from your complexity. Can you do that?

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                    Vote: I like it 0 Vote: I do not like it

                  ur gonna have to help me with that

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                    Vote: I like it +5 Vote: I do not like it

                  Hint: use quantum computer.

              • »
                »
                »
                »
                »
                »
                »
                »
                2 months ago, # ^ |
                  Vote: I like it +5 Vote: I do not like it

                You complexity is $$$O(qlogn + ...)$$$ and as explained, $$$q = O(n\sqrt{n}))$$$. Your algorithm is even worse than his original idea.

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                    Vote: I like it -8 Vote: I do not like it

                  We're not going through all the queries everytime

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                    Vote: I like it +8 Vote: I do not like it

                  ok my bad i just realized

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  2 months ago, # ^ |
                  Rev. 2   Vote: I like it 0 Vote: I do not like it

                  if we already knew all the elements, couldn't we just concatenate the array and process as normal though?