Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

Автор sophisticated1, история, 11 лет назад, По-английски

How to solve the problem from latest Codechef Long Contest :

https://www.codechef.com/FEB16/problems/SEAPERMS

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

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

Let's think of a way construct a permutation: Initially, it's empty. One by one, we add an element. Assume, after that we have permutation p1, p2, ..., pk and pi is recent element. So, we must have: p[i-1] + d > p[i], p[i] + d> p[i+1]. If the sequence we add is non-decreasing, then we just care about the condition p[i-1] + d > p[i]. Clearly, the way we add pi equals to the number of element before pi (in sorted non-decreasing sequence) that greater than p[i]-d and plus one for adding at first position. (*) Therefore, we have a solution in O(m * n * log(n)). In order to improve that complexity, in each query, we maintain the number (*) for each element. And in each query, there are O(D) element is affected. Complexity reduce to O((n + m) * d).

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

How to solve WRDSUM?

  • »
    »
    11 лет назад, скрыть # ^ |
    ← Rev. 4  
    Проголосовать: нравится +14 Проголосовать: не нравится

    Use inclusive-exclusive principle: Almost always F(n) = n. So we start with 2 + ... + n. Let's look how to fix our sum

    • we have to subtract and put instead.

    • we have to subtract and put instead.

    • we have to subtract and

    and put , and instead.

    And so on. If you calculate this properly you will get sth like this

    The formula 2d + ... + xd is a polynomial of degree d + 1 so we can use Lagrange interpolation to get coefficients, or precompute Bernoulli numbers and use Faulhaber's formula. Notice that max D is around .

    Depending on implementation we should get sth like O(D2) or even faster solution. Use python or java to avoid bignum implementation.