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

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

Hello everyone!

Over last few years number of standard algorithms and structures (dfs, FFT, segment tree, suffix automaton, ... Gomory-Hu tree) didn't change much, at least in my perception. Most of fresh tasks require pure creativity (tasks on atcoder.jp being most prominent example) or unusual combination of well-known blocks. Some tasks are even pure combinatorics math problems (I'm a big fan of these).

But I think there still are room to bring some new "primitive" structures. Let's form a list of interesting stuff that are unpopular or unknown!

My first thoughts are palindromic tree and multipoint evaluation (computes values of polynomial of degree n in n points in time).

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

»
7 лет назад, # |
  Проголосовать: нравится +62 Проголосовать: не нравится

DP optimization used in IOI 2016 Aliens
Btw does the multipoint evaluation you mentioned work for any commutative ring , or does it only work for certain special rings?

»
7 лет назад, # |
  Проголосовать: нравится +32 Проголосовать: не нравится

Maybe Wavelet (tree|matrix|array)? I haven't heard about them until recent time.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

The impressive algorithm in recent years for me is solving linear recursion.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    I was very surprised when first saw this problem in 2014 in Petrozavodsk.

    Now (after all this years...) I think the best explanation of this trick is using generating functions. In a nutshell, you need to calculate first n coefficients of , which can be done in using FFT.

    Also, continuing this line, one can calculate first n coefficients of , P(x)a, in using Newton's method.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +9 Проголосовать: не нравится

      I think the simplest explanation is calculating , where f(x) = xk - a1xk - 1 - ... - ak is the characteristic polynomial. You just say that xn = a1xn - 1 + ... + akxn - k and repeat it until only powers less than k remain. It is literally the same as calculating an in the naive way. It also works for big values of n with binary exponentiation in .

      I also was surprised when I heard of it on algebra lesson in the first year in university. Kind of sad that every schoolkid knows how to solve this problem with matrix multiplication but so few people know about this trick.

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +5 Проголосовать: не нравится

      How do you use newton's method to find first n coefficients of P(x)a, and others?

      I find P(x)a case particularly surprising because if there exists such an algorithm, then you can find ab without a factor of .

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +15 Проголосовать: не нравится

        This is what I saw on some chinese paper.

        Calculating the reciprocal of a polynomial is quite well-known. See for example here.

        To calculate ln(A(x)), let B(x) = ln(A(x)). Then by Chain Rule,

        We can find A'(x) in O(n) time and in time. Multiplying these polynomials take another time. Finally, integrate the result in O(n) time.

        Calculating exp(A(x)) is more involved. Let f(x) = eA(x), and let g be a function such that g(f(x)) = 0 = ln(f(x)) - A(x).

        Firstly, we can compute the constant term of f(x) by using the Maclaurin series. Suppose we know the first n terms of f(x), call it f0(x), thus .

        By Taylor's expansion,

        .

        Here g(2) denotes the second differential of g.

        Thus, ,

        Substituting g(f0(x)) = ln(f0(x)) - A(x), we get .

        Thus, it is sufficient to compute the last term to get the first 2n terms of f. Similar to finding the inverse, we can prove that this works in time.

        Now, to calculate P(x)a, then just calculate . Complexity is still .

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
          Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

          But how to calculate the 0th term in exponent? It seems to be impossible if polynomials 0th term isn't zero. Also to integrate the result in you have to know 0th term.

          Btw, the rule you mentioned is exactly Newton's method and it can be used to calculate terms of any proper function.

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

            You're right. I forgot to mention that in calculating log we assume the constant term is 1 and for exp we assume the constant term is 0.

            Thus, before calculating P(x)a we need to convert P(x) to a polynomial with constant term 1. Let cxd be the smallest nonzero term in the polynomial. Then, and we can calculate using the method above because the constant term is 1.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +38 Проголосовать: не нравится

Things came up after WF 2014 (the end of my career):

  1. Two most commonly used technique on ProjectEuler: (a) Berlekamp–Massey algorithm (b) O(n2 / 3) or O(n3 / 4) sieve-like algorithm (I don't know what it should be called exactly)

  2. Novel use of segment tree (It is called "SGT Beats" in China). [Add some description]

  3. Tutte Matrix.

  4. to be continued.

»
7 лет назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

LiChao tree for convex hull trick

»
7 лет назад, # |
  Проголосовать: нравится +21 Проголосовать: не нравится
»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

There are many mathematical things that uses in competitive programming, but I've never used differential or integral in competitive programming problems.

»
7 лет назад, # |
  Проголосовать: нравится +21 Проголосовать: не нравится

Polynomial interpolation always seems like magic to me. Some of my favourite problems that can be solved with it are this and this.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +10 Проголосовать: не нравится

    Also task Infinity Binary Embedding of yours is a good example (can be found here).

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +13 Проголосовать: не нравится

      Yes, I'm very proud of this task. =) It doesn't exactly involve interpolation from values though.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +41 Проголосовать: не нравится

Some open problems regarding "aliens trick" :

  • In the DP case, how can I figure out whether it's "convex" or not easily, without guessing?
  • When is this kind of optimization applicable? It's clearly not only "DP optimization"
  • Seems like this task is also optimizable to O(nlgn) with this trick, but can you also find the way?
  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

    For so-called "jiry_2 SGT", it's conceptually simple. Considering "sum of distinct numbers in each nodes" as the potential function, the 2nd minimum/maximum is to ensure you reduce the potential for each "extra" SGT recursion you make.

    IMO "aliens trick" is Lagrange multiplier. For the APIO task you posted, add to the objective function and try to minimize using optimization tool.

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

      Seems like my english was awful :/ I was wondering how to print the optimal splitting sequence, not only the answer

»
7 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

It is really amazing for me to hear so many extremely advanced techniques...

Perhaps this is a little away from the topic, but I was always wondering how the first person came up with such ingenious techniques. Some of them might just be advanced or improved versions of relatively mature techniques, but the other ones seem considerably original and creative. What is the inspiration behind these techniques? Is it like science that people make improvement based on the previous results?

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

How about Dominator Tree in directed cyclic graph?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +51 Проголосовать: не нравится

    Isn't that older than me?

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится +8 Проголосовать: не нравится

      Maybe it is old for a half-step to legendary like you but for a blue one like me... (I just know about the "name" in Barcelona Bootcamp a while ago :v)

      And I think you look older than it :p

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +2 Проголосовать: не нравится

        But the age of an algorithm is not measured based on when you or me learnt it but based on when it was published/introduced. And Tarjan's paper on fast algorithm for dominator tree was published in 1979 :)

        • »
          »
          »
          »
          »
          7 лет назад, # ^ |
            Проголосовать: нравится -9 Проголосовать: не нравится

          Okay Okay. You are younger than the that old algorithm. :))

          I have a question to ask. From your comment, I guess that you, bloody red coders, seem to learn algorithms from original papers and do your own implementation rather than finding a tutorial on some community. Is it true?

          (Since I want to know if my current way of learning is wrong: find tutorials and search for nice codes from high rated coders to read)