a_gt3_rs's blog

By a_gt3_rs, history, 5 hours 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

»
3 hours 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

  • »
    »
    93 minutes 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.

    • »
      »
      »
      92 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Is it online? if not, why?

      • »
        »
        »
        »
        91 minute(s) ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It doesn't need to be online

        • »
          »
          »
          »
          »
          86 minutes 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))$$$

          • »
            »
            »
            »
            »
            »
            85 minutes ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Can you give more details about the solution

            • »
              »
              »
              »
              »
              »
              »
              68 minutes 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.