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

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

Hello Codeforces!

Sadly there will be no OpenCup round this weekend, but instead I invite you to participate in a mirror of t.me/umnik_team Contest which will be held on Timus Online Judge this Sunday, 12 MSK. This contest was originally held on Petrozavodsk Summer Camp 2018 (if you participated in the camp, please do not participate in this contest). This is an up-to-3-person team contest with ICPC rules (one computer per team). Difficulty level is comparable to OpenCup rounds (not jqdai0815-hard, but certainly not for Div.2).

Author of most of the problems is me, with huge help from Merkurev and one problem from Kronecker.

Hope you will enjoy the contest.

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

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

Friendly warning that one of problems from this contest appeared on Prime New Year Contest, but I guess it's not like results of some mirror of Petrozavodsk contest are very important, so I wouldn't say that this exclude anybody from participating if he just pretends this problem doesn't exist.

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

    Absolutely correct, thanks, I half-forgot that this problem was there, probably because it is not that hard :)

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

      Which one was that?

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

        Don't look if you didn't participate in Prime New Year Contest and going to participate in the mirror.

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

        By this point I can assure you that you know something like half of problems from this contest, no point in you participating there :p

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

          Really? I don't think that this contest was published anywhere, and if I remember correctly, there were no teams from Warsaw in that camp.

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

            On University of Warsaw we usually use problems from Summer Petrozavodsk camps for internal competitions. In particular we used two of your problems yesterday :p

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

              How do you get access to them?

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

                By the courtesy of snark :)

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

                  Weird stuff, this contest is not even on opentrains :)

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

                  Being absent or being added with a two years delay on opentrains is not that uncommon ;p

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

                  I mean, weird that you have access to the contest and it's not even on opentrains. So Snark have time to send the contest to you, but don't have time to upload it to opentrains.

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

          Makes sense, thanks.

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

Is there problems pdf?

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

    You can see the statement by clicking on the problem.

    Or do you want to print it out? I can send you some version, since we changed limits in 2 problems.

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

Really hard problems QAQ

I'm surprised so few people did G, to me it was trivial, just a lot of work. Initially my code was way too slow, then I swapped binary search in baby-step giant-step to the gnu_pbds hashmap and suddenly random instances took like 1.5s. Pretty odd, I thought that binary search could never be beaten.

In C the weight of the tree is just $$$\sum_{i = 1}^{n} deg(i) \cdot i \cdot n - i \cdot (n-1)$$$ so you only need $$$E[deg(i)]$$$ for all $$$i$$$, but that seems to be pretty hard to get. Apparently sampling trees uniformly at random given degrees of nodes isn't easy, so how is counting solutions possible?

How to solve D?

  • »
    »
    6 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится +19 Проголосовать: не нравится

    For D the answer is 4*a-1/3. With the power of WolframAlpha.

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

    $$$ans=4a-\frac 1 3$$$ for $$$a \ge 2$$$

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

    Did you get accepted on G? My solution does not involve computing discrete logarithms.

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

      Yeah. I don't know any better way to get the size of the generated subgroup than to take $$$(p-1) / gcd(p-1, a_{1}, \dots, a_{k})$$$ where the values in the interval are $$$g^{a_{1}}, \dots, g^{a_{k}}$$$ for some generator $$$g$$$.

      So I used discrete logarithm to turn the input values into exponents of the generator, and multiplication into addition. Then I used the standard technique of interval GCD segment tree with addition to get the result.

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

        It shouldn’t be fast enough though... at least if p is 10^12 I don’t think this approach can pass.

        To find order of subgroup, it’s just the lcm of all order of elements as the multiplicative group is cyclic. It’s easy to maintain if you consider ratios of consecutive elements.

        EDIT: I see what you mean now, the complexity is like sqrt(p(n+q)) I guess. Still, it can be done without polynomial dependence on p.

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

          $$$p$$$ was at most $$$10^{9}$$$ in the problem

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

          When I came up with this problem, I didn't know that you can solve (add on segment, gcd on segment) with segment tree. Then I_love_Tanya_Romanova solved it with this approach during testing. Our implementation of this works about 6.5 seconds which was enough in original contest, but not in this version. Though I didn't try to optimize it, looks like very fast hashtable is the key.

          My original solution had complexity $$$O((n+q) (\log n + \log p) \log p$$$, and it works around the same time. To get lower times I did some insane optimizations, main one is this: I needed to calculate $$$O(\log p)$$$ powers of the same number in one query, and instead of doing $$$O(\log p)$$$ binary exponentiations, I did 5 or 6 layers of sqrt-decomposition-like thing, getting $$$O(k(\sqrt[k]{p} + \log p))$$$ (where $$$k=6$$$), which is 2-3 times faster.

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

    You know degree for all not_-1 vertices, and all other vertices are the same, so they have equal $$$E[deg(v)]$$$. Sum of all deg is $$$2n-2$$$, so you know $$$E[deg(v)]$$$ for all $$$v$$$.

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

    Maybe G is hard because people like me don't know what group means in mathematics?

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

      There were the definitions, right?

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

        I saw the sample and didn't scroll beyond. Sorry.

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

        It's not like you are already familiar with a concept right after reading definitions.

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

          This is true. But this problem is about the multiplicative group modulo prime number, with which participants are mostly familiar, things like existence of primitive root are known. So even if you didn't know what is group, I think you could read the definitions and understand that you are dealing with object you know.

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

Help, how to solve B?

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

    let $$$A = {a_1,a_2,\cdots,a_k} $$$ (sorted by dfn)

    $$$f(x)$$$ = the sum of the weight from root to x.

    $$$ans = f(a_1) + f(a_2) + \cdots + f(a_k) - f(lca(a_1,a_2)) - f(lca(a_2,a_3)) - \cdots - f(lca(a_k,a_1))$$$

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

How to solve A & E?

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

    A: First of all, we consider that whether a single 0 or 1 occur in the rule. Obviously, only one of 0 or 1 occur in the rule, Otherwise the answer is N or -1. Suppose there exists 0 but not 1, because it is a prefix-free system, a fact is that if W can be decoded, only if 0^k+W can be decoded. For any S, if we consider restrciting a suffix cannot be decoded, we only have to think about how to divide the prefix part. Because 0 can be decoded, and each part we devided at least contains a 1, so we can only divide into p(the number of 1s) parts. We can only create this way by connecting every 1 with the continuous 0s. Now the problem becomes finding the shortest prefix that cannot be decoded and the answer should be added by the number of 1s. We can easily find it by reversing those strings and building an AC-Automaton.

    Well, I think it is a quite good problem and also a nice contest. Many thanks to Umnik~

    PS: I actually translate this solution from my solution in Chinese written in August,2018. Maybe I miss some important details or have some mistakes.

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

    For E, $$$O(n^3)$$$ is obvious but got TLE. I guess some methods like FFT/NTT would be used to optimize it (since 40961 is a modulus of NTT). But I have no clue.

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

    E: We need to compute $$$\sum((s[i] == 0) \times C(i, x)\times C(n - i - 1, y)$$$ for each $$$x, y$$$. Fix $$$y$$$, it turns out to use FFT/NTT.

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

      Sorry, I don't understand. Fix y, then how to change it to a convolution?

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

      Could you be so kind and elaborate a bit more on how to reduce this sum to convolution? I tried to calculate $$$f(l, r)$$$ — the number of subsequences of length $$$l + r + 1$$$ with $$$(l + 1)$$$'th element being $$$0$$$. I.e. I tried to preprocess some sums and the answer for length $$$k$$$ would be calculating $$$a_l = f(l - 1, k - l)$$$ and outputting $$$\sum_{i=1}^k a_i \cdot (C(n, k) - a_i)$$$. I computed $$$f$$$ using divide and conquer and NTT that is in $$$\mathcal{O}(N^2 \log^2 n)$$$ which is too slow. Could you hint further how can one achieve $$$\mathcal{O}(N^2 \log n)$$$ if that is the intended complexity?

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

      Good afternoon, could you please send the solution to problem 2122 with acm.timus.ru I would be very grateful to you https://acm.timus.ru/problem.aspx?space=1&num=2122&locale=en

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

Scoreboard of original contest, if anyone interested.

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

How to solve I & F?

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

    I`ve passed F with just bruteforce from a highest weight (but I have nothing to prove it).

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

      Hmm. I did the same thing except memorizing, so it gave TLE. I was thinking that but didn't implement.

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

      Notice that there are at most two transitions for each state. ($$$W_i \ge \sum_{j<i} W_j$$$) And another upper bound is $$$w_i$$$.

      The time complexity is $$$O\left(\sum_{i=1}^{n} \min (2^{n-i},w / 2^{n-i})\right)= O(\sqrt w)$$$.

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

    I: Lucas's theorem. We need to compute $$$\sum{C(n, i)\times C(n - i, i)}$$$. Represent $$$n$$$ as $$$(a_1a_2...a_k)_p$$$. So we concern only $$$i$$$ such that its $$$p-base$$$ representation $$$(b_1b_2...b_k)_p$$$, $$$2b_i \le a_i$$$.

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

How to solve H without obvious $$$\mathcal{O}(n \log^2 n)$$$ interpolation followed by $$$\mathcal{O}(m \log^2 m)$$$ evaluation (which is too slow)?