nhphuc's blog

By nhphuc, history, 12 months ago, In English

Summary: Given an array $$$A$$$ with $$$N$$$ elements. Find the largest continous subbarray $$$(l,\ r)$$$ of $$$A$$$ that: $$$max(A_l,\ A_{l + 1},\ ...,\ A_r)\ \vdots\ min(A_l,\ A_{l + 1},\ ...,\ A_r)$$$. Print the value $$$r - l + 1$$$. constraints: $$$n\leq 6\times 10^5,\ a_i\leq 10^5$$$.

Subtasks:

  • $$$n\leq 500$$$ and $$$n\leq 5000$$$: for $$$O(n^2)$$$.

  • $$$a_1\leq a_2\leq ...\leq a_n$$$: for dp $$$O(n\ log\ n)$$$.

  • $$$a_i\leq 1000$$$: dont know how to do.

  • $$$n\leq 10^5$$$: dont know how to do.

  • No additional constraints: dont know how to do.

Please help me with this problem, thanks for your help and attention. Have a good day !

  • Vote: I like it
  • +18
  • Vote: I do not like it

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

Auto comment: topic has been updated by nhphuc (previous revision, new revision, compare).

»
12 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

What is ⋮

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

    $$$x\ \vdots\ y$$$ mean $$$x$$$ can be divided by $$$y$$$ sir

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

      Cartesian tree and sieve should solve in nlog^2n if I'm not mistaken.

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

        For $$$n\leq 6\times 10^5$$$ I don't think it will pass.

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

          If N = 6 * 10^5 and C = 10^5, then the exact complexity is something like C + NlogNlogC, which I think is fine.

          I haven't thought it out completely but it might be worth a try.

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

            Sorry but do your solution need to visit all divisors of a_i ?

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

              We can sieve from the minimums instead of checking the factors of the maximum. 1 visits n numbers 2 visits n/2 numbers 3 visits n/3 numbers and so on

              H_n = n/1 + n/2 + n/3 + n/4 + ... + n/n = O(nlogn)

              If we keep track of the min/max ranges for each number (O(n) using a cartesian tree, for example) we can speed things up greatly.

»
12 months ago, hide # |
Rev. 3  
Vote: I like it +20 Vote: I do not like it
Solution
»
12 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

hello, is there a submission link available for this problem?

»
12 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

My idea is:

  1. if minimum(a) = 1 then answer is n, so assume all a > 1
  2. build ranges where each element is a minimum, and where it's maximum
  3. build sparse table for (min, max) on range
  4. perform sieve for every mn iterate all mx that are multiples of mn, and find maximum intersection of minints[mn] and maxints[mx]

Not sure how to properly evaluate complexity, but seems like $$$O(n \log A)$$$.Tested again random input this works in

n=10^3 = 3.4285ms 
n=10^4 = 5.819041ms 
n=10^5 = 34.58ms 
n=10^6 = 239.952375ms 
full code
  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    The judge of this problem just has cpp, python, pypy and pascal so I can test this for you but an $$$O(n\ log\ A)$$$ solution can passed this problem (if get no WA :P).

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

      Ask AI to translate code without test section to cpp, or try implementing idea by yourself, a little long, but simple.

      In the test section there are small tests against slow bruteforce solution, so I don't believe it could get WA. TLE maybe because 4 nested loops look really scary, maybe it would be necessary to iterate over smaller of maxints[mx] and minints[mn] first.