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

Автор Endagorion, история, 5 лет назад, По-русски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Проголосовать: нравится
  • +77
  • Проголосовать: не нравится

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

Почему рейтинг не всем дали?

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

Why does 63503240 gives TLE in div2 B2?

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

I solved D, with a different approach(after contest).
I calculated divisors of $$$x^k$$$ for every $$$x$$$ such that 1 <= $$$x$$$ <= $$$10^5$$$ and $$$x^k$$$ <= $$$1e10$$$.Since $$$x$$$ can be only in range $$$1$$$ to $$$10^5$$$ in worst case, we can calculate the divisors of $$$x^k$$$ using prime factors of $$$x$$$. Caluculating prime factors of $$$x^k$$$ is easy if we know prime factors of $$$x$$$, we just need to multiply power of every particular prime factor by $$$k$$$. Since we know divisors of every $$$x^k$$$ we can easily count pairs such that $$$Ai*Aj$$$ = $$$x^k$$$.

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

    I don't see your "Accepted" for this problem and how would you then calculate the answer not in an at least quadratic time? It doesn't seem like a good solution to me.

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

      Link to Submission.
      I already mentioned that i solved it after contest.
      Time complexity of my solution is $$$ (\Sigma_{i=1}^{10^5} divisors(i^k)) * C$$$ (let C be some constant) for calculating divisors,and worst case of this approach occurs when k = 2 because in this case we have to calculate divisors of $$$10^5$$$ numbers. When i computed on my pc they were roughly $$$6*10^6$$$ which is not much for a problem with 2 sec TL.

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

        Oh, I thought that I see all your submissions when I go to your profile but apparently I don't. Thanks for the link.

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

        Thanks for your method to calculate divisors. I used a similar overall solution but the only difference was the method in which I tried to calculate divisors. It gave a TLE for $$$k==2$$$ For each x such that $$$ x^k<(10)**10 $$$, I calculated the divisors using $$$O(\sqrt(x))$$$ method. Which apparently miserable fails for $$$k==2$$$ but works fine for all others

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

    See this for finding divisors using prime factors.

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

Can someone tell me what is wrong in my coding approach for Power Products(D)

I am sorting the array and using two pointer approach to find possible pairsI

63471990

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

Has the tutorial not been made or there is some bug.It is showing tutorial not available for problems D-G

Edit:resolved

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

    The analysis is complete, but there is an issue with loading it from Polygon automatically. This usually resolves itself eventually.

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

      It has not been uploading for me for about 30 mins now, could you please resolve it or tell how to resolve the same. Thanks!

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

in Problem E what is the best RSQ can be used with a few implementation cause i thought of segment tree so that we have n segment tree of base m and m segment tree of size n but it would be a lot of implementation so what do u think ?

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

In problem $$$C$$$, why does $$$n-kp$$$ has to be at least $$$k$$$ can someone please throw some light on it?

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

Please look upon the issue of editorial.It's showing that "Tutorial is not available"

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

can someone explain how to solve div2E/div1C , in editorial it's not clear about defination of D,R arrays?

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

It would be great if someone can explain me easier way solution of div2-C. I cant understand the solution and I,m not so fimiliar with binary numbers, bit cnt etc.

Thanks a lot. :)

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

    Let the minimum number of $$$p$$$-binary numbers required to represent $$$n$$$ be $$$l$$$. We start from $$$l = 1$$$ and increment $$$l$$$, testing its possibility. If it's possible in $$$l$$$ $$$p$$$-binary numbers, then that means that $$$n = (\text{sum of }l\ \text{powers of}\ 2) + lp$$$, because we get a $$$+p$$$ contribution from each of the $$$l$$$ $$$p$$$-binary numbers. So we need to check if $$$n - lp$$$ can be represented as a sum of $$$l$$$ powers of $$$2$$$, not necessarily distinct.

    Now you can represent a number uniquely in any integral base greater than 1. It will result in a unique representation. Now given $$$n - lp$$$, you need at least $$$\lfloor log_2{(n-lp)} \rfloor + 1$$$ bits to represent $$$n$$$, and that is the binary representation of $$$n - lp$$$. So we get one condition that $$$l \geq \lfloor log_2{(n-lp)} \rfloor + 1$$$.

    Consider the example: $$$n-lp = 2^2 = (100)_2$$$. We can write this as $$$2^2 = 2^1 + 2^1 = 2^0 + 2^0 + 2^1 = 2^0 + 2^0 + 2^0 + 2^0$$$ In each subsequent representation we are breaking a power of $$$2$$$ down and adding one term in the representation. This shows us that we can represent $$$2^a$$$ in $$$1$$$ to $$$2^a$$$ terms, therefore we can represent $$$\sum 2^a$$$ in $$$\sum 1$$$ to $$$\sum 2^a$$$ terms. If we choose $$$a$$$ from the binary representation of $$$n - lp$$$, $$$\sum 2^a = n-lp$$$ and $$$\sum 1 = \text{sum of bits in}\ n-lp = \sigma$$$ (say). So $$$l$$$ must satisfy $$$\sigma \leq l \leq n-lp$$$. In GCC, __builtin_popcount(n-lp) can be used that gives the value of $$$\sigma$$$ (sum of bits).

    Now $$$n \leq 10^9$$$ and $$$p = 1000$$$, so number of bits in $$$n-lp$$$ should be the same as that in $$$n$$$. A satisfactory upper bound should be 34. Start from $$$l = 1$$$ to $$$34$$$, and check if $$$\sigma \leq l \leq n-lp$$$; if it's true, then you have your value of $$$l$$$.

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

My approach for D:

Let $$$f_{1}$$$ be a function such that $$$f_{1}(a)=b$$$ for $$$1 \le a \le 10^5$$$ where $$$b=p_{1}^{c_{1}}p_{2}^{c_{2}}...p_{m}^{c_{m}}$$$. Here $$$p_{i}$$$ is a prime and $$$c_{i}<k$$$.

Let $$$fr$$$ gives frequency of an element in given array. Hence for $$$1 \le i \le 10^5$$$ do $$$freq[f_{1}(i)]=freq[f_{1}(i)] + fr[i]$$$.

Now, let $$$f_{2}$$$ be a funtion such that $$$f_{2}(a)=b'$$$ where $$$b'=p_{1}^{k-c_{1}}p_{2}^{k-c_{2}}...p_{m}^{k-c_{m}}$$$.

The answer is ans

$$$ ans= \begin{cases} ans \enspace + \enspace freq[f_{1}(i)] \times freq[f_{2}(i)], & \text{if } f_{1}(i) \ne f_{2}(i)\\ ans \enspace + \enspace freq[f_{1}(i)] \times (freq[f_{2}(i)] - 1)/2, & \text{otherwise} \end{cases} $$$

Note: Chech if $$$f_{1}(i)$$$ has already been calculated as $$$f_{1}(i) = f_{1}(j)$$$ for $$$i \ne j$$$.

Link to code

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

Alternative solution to G:

  • Consider the dumb $$$O(N^\alpha 3^N (\sum a_i)^2)$$$ DP solution that just finds numbers that can be made from each subset. It's too slow.
  • Add bitsets. It's still too slow.
  • Consider a different $$$O(N^\alpha 3^N (\sum a_i)^2)$$$ DP solution that goes in the reverse direction and calculates for each subset and number "if we can make this number using this subset, we win". It uses the results of the previous DP, because when we want to make $$$x$$$ (or $$$xK, xK^2, \ldots$$$) using subset $$$i$$$ and we can definitely make $$$y \le x$$$ using a subset $$$j \subset i$$$, then we want to make $$$x-y$$$ using the subset $$$i-j$$$. It's still too slow.
  • Combine these two DPs in a meet-in-the-middle approach. Due to symmetry, we only need to consider cases where the subset $$$j$$$ above is smaller than $$$i-j$$$, or equally large (with some tiebreaker like j < i-j). As soon as we find out that we both can make number $$$j$$$ using subset $$$i$$$ (first DP) and if we make it, we win (second DP), we can stop and use the first DP to construct a solution.
  • The first DP now only needs to consider subsets with size $$$\le N/2$$$. The theoretical bound isn't much better, but in practice, we have much fewer states to consider both because there are less subsets and much fewer numbers to make using small subsets.
  • The second DP only needs to consider the remaining subsets and it will either quickly find a solution or have very few states to process, so it's pretty fast either way. Intuitively:
    • If the first DP finds many numbers, the chance that the second DP also finds many numbers (using those found by the first DP) and therefore that it quickly stumbles upon a solution is high.
    • If the second DP finds few numbers, the first DP will have difficulty forming many numbers we want to make using large subsets. Small subsets should automatically consume little time, since they have fewer subsets and in the split $$$i \rightarrow (j, i-j)$$$ described above, if the sets $$$j$$$ and $$$i-j$$$ are both processed by the first DP, we don't gain any states in the second DP.
    • If $$$i$$$ is large and $$$j$$$ is kinda large, then $$$i-j$$$ is much smaller than $$$i$$$ and we already get a small state. On the other hand, when $$$i$$$ is large and $$$j$$$ is very small, then there are few numbers we can make using the subset $$$j$$$.

Time complexity: 1200 ms.

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

    So someone cheesed this problem after all, huh. Nice job!

    With enough stress-testing I've managed to time out this solution very slightly with this test:

    16 3
    2 143 158 16 58 56 161 101 89 100 250 7 334 92 103 251
    
    • »
      »
      »
      5 лет назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      11

      Main observation: the loop "for each set bit in v1, shift v2" allows a massive speedup if v1 has just one set bit, which is very often the case for small subsets. (I already tried your hack.)

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

    Could anyone please explain "dumb" dp? I don't get what is the dp state there.

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

      "Using a subset $$$S$$$ of the given numbers, can we create a number $$$j$$$?" The values of the states are 0/1, there are $$$O(2^N \sum a_i)$$$ of them.

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

        Thanks! How do you end up with $$$N^{\alpha}$$$ in the complexity?

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

          Choose $$$\alpha$$$ arbitrarily. Then, there's always $$$N^\alpha$$$ in any complexity. In this case, it's the exponential and sum that matter, so I didn't bother thinking what $$$\alpha$$$ is.

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

I waited for like 10 MINUTES and there was still no editorial. Can anyone who can see the editorial for Div. 1 B to Div. 1 F consider posting the editorial on somewhere else for others' convenience?

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

I got TLE in div2 B2 when contest final consequence came out.But accepted it after contest with exactly the same codes.

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

Is this an alternative solution to problem F(Div. 1)?

Again, solve it backwards.

Consider elements in [L, X] can reach X in no more than K steps. Then, elements in [L', X] can reach X in no more than K + 1 steps, where L' = min_i{pre[i], L <= i <= X} where pre[i] = the last occurance of ch[i] before i(ch[] is the string in the input).

Let's try to fix X. Then, the process above forms a tree structure, and what we need to compute is the sum on the path from X to the root.

Consider how does the tree change when 1 is added to X. The parent of an interval [[the minimal Y such that min{pre[Y...X]} >= pre[X]], X] will be modified to pre[X] while the other vertices of the tree remain unchanged. Put the intervals with the same parent together and we only need basic operations in dynamic trees to fix it.

Use Link Cut Tree or Euler Tour Tree(I'm not sure because I don't know ETT well) to solve the problem in O(n log n).

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

For Div2 C can someone explain the case when P is negative answer for K still won't cross 31

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

    Let $$$p < 0$$$, then the maximum value of $$$n - 31p$$$ will be $$$10^9+31000$$$ which can be represented with 30 binary digits (less than 31). It's obvious that all the numbers less than $$$10^9+31000$$$ can also be represented with no more than 30 binary digits. So $$$k=31$$$ will always be possible.

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

      But whose telling you to stop at 31p for p<0 ,I can still keep on subtracting it

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

        We wish to find the minimum answer. So if we know that surely 31 is a possible answer, then we won't check for numbers greater than 31.

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

In solution of D there is a small mistake. It is given that 360 = 2^3 * 2^2 *5 but it should be 360 = 2^3 * 3^2 * 5

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

Could someone give me a elaborated explanation for problem Div2-C. The Edtiorial is so hard to grasp, especially the range of all $$$k$$$ value. Thanks

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +2 Проголосовать: не нравится
    /*
    Let x = n-31*p
    There are two possibilities: 
    1.  x >= 31
    2.  x < 31
    
    For the first case, the maximum value of x is (1e9 + 31*1000) < (2^31). So, 31 <= x < 2^31. Hence, x can always be represented as exact 31 powers of 2's. However, there is a possibility that we can achieve the same with fewer. So, just iterate the value of k from 1 to 31 and check for the minimum value.
    
    For the second case, n < 31*(p+1). Since, n>0 and n<31*(p+1) , 31*(p+1) >0 . So, p > -1 or p >=0 (in the editorial there is a mistake, it should be p+1>0 not p+1<0). If (k>31) , -kp < -31p, So,n-k*p < n-31*p < 31 < k. Hence, n-k*p < k (not possible, as it has to be at least k). So, k <= 31.
    */
    
    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you very much! Excellent Explanation.

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

        But what happen if I let x = n-1e9*p? I am confused that: I want to represent $$$n-kp$$$ not just $$$n-31p$$$.

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

    Hint : How to represent a number as exactly k powers of 2.

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

Что значит Разбор недоступен, начиная с задачи D по F?

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

Why does https://codeforces.me/contest/1225/submission/63542673 give TLE using g++, but works with MSVC???

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

    I just know why the code got TLE using g++. Because there may be 1e5 test case. And for each test case, the value of k can be 1e6. Then the code will run Line 24 1e5*1e6 times. It got TLE here.

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

Почему https://codeforces.me/contest/1225/submission/63542673 ловит TLE c g++, но берёт accepted с MSVC??? Помогите, пожалуйста.

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

    Потому что вы инициализируйте каждый новый тест массив длиной $$$k$$$ нулями. Таким образом ваша сложность — $$$O(tk)$$$, что, если вы внимательно посмотрите на условие, определенно будет ловить TLE. Используйте map.

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

In case(like me ) you are having a hard time implementing problem D tutorial (DIV 2) here is a implementation of the given approach
https://codeforces.me/contest/1225/submission/63557938

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

Can someone explain B2 to me..

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

    Think in terms of sliding window u need to count minimum unique elements at a given window and keep sliding window till the end. See my submission

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

Typo in ur editorial of D -> factorisation of 360 should be 2^3 3^2 5^1 u mistyped 2 in place of 3

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

Maybe it will be useful for users who will try to solve this task later. I've found that the following solution passes all authors' tests although it's incorrect: Let's consider DP[N][X][Y] — it is 1, if we can apply such consequence of operations to N-length prefix of an array so that last two numbers are X and Y, and 0 if we can't. Then DP[2][A[1]][A[2]] = DP[2][A[2]][A[1]] = 1, and for each i from 2 to N and X, Y from 1 to 2000 if DP[i — 1][X][Y] == 1 then DP[i][f(X+A[i])][Y] = DP[i][Y][f(X+A[i])] = DP[i][X][f(Y+A[i])] = DP[i][f(Y + A[i])][X] = DP[f(X+Y)][A[i]] = DP[A[i]][f(X+Y)] = 1. So in the end we just have to check if for some X, Y such that f(X+Y)=1 DP[i][X][Y] == 1, and restore the answer. The problem is that in general it's not true that f(f(a+b)+c) = f(a+f(b+c)). Test that breaks this solution: 8 4 39 39 51 13 38 66 98 86

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

I found it interesting that my friend skip1978 solved div1 E using the random method.

I wonder how high the correct rate of this method is.

63493030

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

    Very, very high at least without trying to design a countertest. It took me many hours of runtime to find a test where it fails — specifically, where the probability that a random sequence of operations works is low enough... although maybe I could buy processing power in the cloud and find more. And that's still just because it reshuffles $$$N$$$ times. With some optimisations, finding a test where it fails would be near impossible because $$$N$$$ is so low.

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

Can someone please tell me what is wrong with my prime factorization in this code for D : Code 1

Also , after changing it I got ac Code 2

Thanks in advance !

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

    I think the code is wrong because of Line 16. The end value of x may be 2 when the begin value of x is 2. Then it will not think 2 has the prime factor 2. the code will be wrong if there is 2 in the input.

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

I cant understand in D one thing. What if we have ones? This solution doesn"t work in this case.

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

Can somebody tell me how to solve div2 B2 in O(n) as maintaining count with array will give TLE?

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

Can someone explain problem E to me?

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

In the task D how can we find factorization of every number in the sequence with sqrt(max ai) or log2(max ai) complexity?__

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

    Perhaps it means sqrt(max a[i]) for each number separately so total of n*sqrt(max a[i]) (or nlog(max a[i]))

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

I am unable to understand E's editorial. please help.

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

Thanks for Fast Editorial.

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

Почему в задаче с p + 1 < 0, при n − 31 (p+1) < 0? При n n = 10 и p = 1 первое условие неверно, а второе — верно. И почему n — 31p < 2^31 при n >= 31p + 31, а не при 30p + 30, если так проверяемых k меньше?

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

In problem D, we don't need to store the whole list. We know that each list gives us unique number so we just store that number and its frequency.

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

why 197067161 gives TLE? i'm really sure that code is O(n) per test case

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

My $$$O(n^\frac{5}{3})$$$ code works for D, just thought it was interesting and curious that it got accepted.

On a second look, I think it can be hacked easily. The test cases for D were quite weak.

233245894

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

Why don't the dickhead authors provide their own code ?