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

Автор nhphuc, история, 19 месяцев назад, По-английски

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 !

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

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

What is ⋮

»
19 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +20 Проголосовать: не нравится
Solution
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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

»
19 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

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
  • »
    »
    19 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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).

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

      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.