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

Автор Gheal, история, 3 года назад, По-английски

A — The Ultimate Square

Author: Gheal

Hints
Solution
Code (C++)
Rate Problem

B — Balanced Substrings

Author: Gheal

Hints
Solution
Code(C++)
Rate problem

C — Zero Sum Prefixes

Idea: Gheal, Solution: IgorI

Hints
Solution
Code(C++)
Rate problem

D — ConstructOR

Author: Gheal

Hints
Solution
Code(C++)
Rate problem

E — Yet Another Array Counting Problem

Author: Gheal

Hints
Solution
Code(C++)
Rate problem

F — Circular Xor Reversal

Idea: Gheal, Solution: IgorI

Hints
Solution
Code(C++)
Rate problem

If there is anything wrong or unclear in this editorial, feel free to ping me in the comments.

Разбор задач Codeforces Round 833 (Div. 2)
  • Проголосовать: нравится
  • +160
  • Проголосовать: не нравится

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

Good Round! Thanks for the fast editorial!

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

My Solution for D:

Check no solution:Note $$$cal(x)=max(i),2^i|x$$$,if $$$cal(d) \gt min(cal(a),cal(b))$$$,no solution.

Otherwise,Let's construct the solution.

First,let $$$d»=cal(d),a»=cal(d),b»=cal(d)$$$,calculate the $$$x$$$ for the new $$$a,b,d$$$.When outputting the answer, we only need to output $$$2^{cal(d)}x$$$.

How to construct such $$$x$$$?The key point is make $$$x=(2^{key}-1)+2^{key}X$$$,($$$key=30-cal(d)$$$).

This is actually a problem of solving congruence equations:$$$(2^{key}-1)+2^{key}X=0(mod\space d)$$$,use exgcd to get such $$$X$$$.

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

    Here is another solution for D:

    If $$$min(lsb(a),lsb(b)) \lt lsb(d)$$$, there is no solution. Because $$$lsb(d*k) \gt =lsb(d)$$$ so their $$$lsb$$$ can never be equal. Hence, they can't also be equal.

    Otherwise; let $$$ans = 0$$$ initially, we want to fill bits of $$$ans$$$ such that it will be multiple of d, and $$$ans$$$ will be *superset of $$$a|b$$$.

    Let's iterate over bits of $$$ans$$$ $$$0$$$ to $$$29$$$

    If $$$i$$$'th bit of $$$ans$$$ is $$$0$$$ then add $$$d * (2^{i-lsb(d)})$$$ to $$$ans$$$. Now that bit will be $$$1$$$ and it will contain $$$a|b$$$ anyway.

    Since $$$d$$$ has at most $$$30$$$ bits and our target is to fill first $$$30$$$ bits and there must be an intersection, our answer will require at most $$$30+30-1=59$$$ bits and this fits constraints!

    Here is my submission.

    (*Note : $$$X$$$ is superset of $$$Y$$$ if $$$Y$$$ is subset of $$$X$$$.)

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

      tolbi "If i'th bit .... contain a|b anyway." Can you please explain this line? Like how did you come up with this approach?

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

        If $$$i$$$'th bit of $$$ans$$$ is $$$0$$$, when we add $$$d*(2^{i-lsb(d)}$$$ to $$$ans$$$, actually we shifted $$$d$$$ to intersect $$$lsb(d)$$$ with that bit. Since $$$lsb(d)=2^{i}$$$ and $$$2^i$$$ & $$$ans = 0$$$ after shifting, if we gather them then $$$i$$$'th bit will be $$$1$$$. Since we filled first $$$30$$$ bits with $$$1$$$, it will be superset of $$$a|b$$$.

        Actually first $$$30$$$ bits except bits that is smaller than $$$lsb(d)$$$ are $$$1$$$. But since $$$lsb(d) \le lsb(a|b)$$$, it is meaningless. There is no bit such that $$$bit$$$ & $$$(a|b) = 1$$$ and $$$bit$$$ & $$$ans = 0$$$. I wrote above comment incorrectly you must to start from $$$lsb(d)$$$ instead of $$$0$$$ but when coding it, (1LL<<bit) gives $$$0$$$ if $$$bit$$$ is negative. So you can start from $$$0$$$ too if you used shifting that way.

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

Problem D can also be solved using Chinese Remainder Theorem. First step is the same as stated in solution given above: proccess cases, when answer is -1, and then you can just find X, s.t. X = a|b (mod 2^30), and X = 0 (mod d'). Where d' comes from d = 2^i * d', where d' is odd. The answer is under 2^60, since 2^30*d < 2^30*2^30 = 2^60

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

    Can you explain the crt method in your code? I did like usual chinese remainder theorem and to take an account that x is congruent to 0 mod d. I took the remainder 0 as d and did normal chinese remainder theorem. It did not work. I saw that you are doing something in reverse fashion, but could not understand it. I appreciate your idea anyway! Thanks and eagerly waiting for your reply and my submission is at above comment.

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

      Basically, I used Garner's alrorithm for 2 co-prime numbers: d' and 2^30. You can read more about that here: https://cp-algorithms.com/algebra/chinese-remainder-theorem.html#garners-algorithm I don't really know what is wrong with your formula above, since it's quite messy, but maybe you can find your mistake by reading this article

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

        I finally got AC using your approach and normal congruence relation.

        We have two congruence equations as

        x=(a|b)mod(1l<<30) ---> 1

        x=0mod(d') ---> 2

        That means x=d'*k, replacing this in 1 gives

        d'*k=(a|b)mod(1l<<30)

        k=(a|b)(1/d')mod(1l<<30)

        Solve this we can find k and k*d is the answer

        Hope it might help someone.

        Today i learned that if we have remainder 0 in chinese remainder theorem we can convert x into multiple of that modulus and solve it instead of doing normal chinese remainder theorem which might yield a wrong answer.

        181131228

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

          I think you are getting something wrong. There is only 1 chinese remainder theorem, but there is also an algorithm to construct the number from remainders modulo co-prime set of numbers. Chinese remainder theorem works for any remainders, as long as they are remainders modulo co-prime set of numbers. I don't understand what is normal chinese remainder theorem you are referring to.

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

    thx, got x * 2^30 + (a|b) = 0 (or d) mod d => x * 2^30 = (d — (a|b) % d) mod d => x * 2^30 = c => x = c * inv(2^30,d)

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

I think the problem b was difficult than usual.

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

Huge gap between A and B.

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

Problem A is so dumb, just look at it, a lot of people did it under 1 minute, which is time to read the statement alone. Its enough just to go to test cases and see the STUPID pattern

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

I had the O(100*n) solution for B TLE: https://mirror.codeforces.com/contest/1748/submission/180630056 How come?

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

E is easy but I have no time :(

use cartesian-tree and dp.

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

is it possible to solve B in python 3 , I see no accepted solutions. would be greatly appreciated if someone can help me with it. thanks

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

Wow so fast tutorials .Great Contest .Problems were great . Thank u :)

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

I dont know why I'm experiencing a TLE for this code on my last pretest for problem C T_T any idea??

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    s = 0
    res = 0
    flag = 0
    d = {}
    maxi = 0
    for i in arr:
        s += i
        if flag == 0 and s == 0 and i != 0:
            res += 1
        if i == 0 and flag == 0:
            d[s] = 1
            flag = 1
            maxi = 1
        elif i == 0 and flag:
            res += maxi
            s = 0
            d = {}
            d[0] = 1
            maxi = 1
        elif flag:
            if s in d:
                d[s] += 1
            else:
                d[s] = 1
            if d[s] > maxi:
                maxi = d[s]
    res += maxi
    print(res)
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Really nice round. I had guessed that if $$$min(lsb(a), lsb(b)) \lt lsb(d)$$$, it might be impossible in problem D but can't prove it. Could someone provide a proof of why that is always true?

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

Am I the only one who stupidly used Euler's Theorem to find inverse modulo in D?

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

Can anyone explain me why am I getting TLE in Problem C here's my code https://mirror.codeforces.com/contest/1748/submission/180659944

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

My solution for B: for each i such that 1<=i<=n we find for each possible number of distinct elements what is the range L,R where this occurs. Then for each range we check where is the first index j such that the subarray [i,j] is bad, and subract R-j+1 from all possible subarrays. Time complexity is O(100nlogn) because we can find the ranges and check for bad subarrays using binary search. You can check my code to understand more

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

Thanks for the fast editorial. I quite liked problems A-C. However, on problem D I feel like there should have been a constraint that D is a prime that is not 2. Because most of the ideas from D still apply, but finding the modular inverse is much easier. Or it could have also been split into an easier and harder version, with the easier one having D as a prime. I feel that C-D gap was quite large.

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

can anyone please explain problem B...

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

I cant solve b during contest, but still I think that it was a nice problem

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

I think my solution for D is somewhat simpler (at least for me) to understand:

First, it is impossible if the (where $$$lsb$$$ is the least significant bit) $$$lsb(a) \leq lsb(d)$$$ or $$$lsb(b) \leq lsb(d)$$$ because we are trying to find an $$$x$$$ such that $$$a|x$$$ and $$$b|x$$$ are both multiples of $$$d$$$. When we multiply a number $$$h$$$ by another $$$k$$$ and look at the result in binary, the result is the sum of multiplying the first by each of the bits of the second, which would imply that $$$lsb(h*k) \geq lsb(h)$$$ and $$$lsb(h*k) \geq lsb(k)$$$.

After we figure this out and deal with that case, the rest is easy. First lets say $$$m_i$$$ is the $$$i_{th}$$$ bit of $$$m$$$. We want to find a multiple of $$$d$$$ (lets call it $$$k$$$) where there is no bit $$$i$$$ such that $$$x_i=1$$$ and $$$k_i=0$$$. If we find this then all we need to do is apply a bitwise OR to $$$x$$$ in order to make $$$x=k$$$. This is always possible through the following algorithm:

Lets make $$$x=a|b$$$ and $$$k=d$$$ initally, then we iterate through the bits of both,

If $$$x_i=k_i$$$ then we can can ignore this bit.

If $$$x_i=1$$$ and $$$k_i=0$$$ we can left shift $$$d$$$ some number of times until the $$$lsb(d)$$$ is at the $$$i_{th}$$$ bit and then add this to $$$k$$$. This would not change any of the bits that we have already iterated over, would maintain that $$$k$$$ is a multiple of $$$d$$$, and would make $$$k_i=1$$$.

Now, there is no bit $$$i$$$ where $$$x_i=1$$$ and $$$k_i=0$$$, so we can just make $$$x = k$$$ by making $$$x=x|k$$$

Im pretty sure this is a naive solution compared to one using a single eqution but still I enjoyed coming up with it and think it is a little easier to understand.

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

In problem F the number of operations can be improved from $$$\frac{3}{2} m^2 + O(m)$$$ to $$$\frac{5}{4} m^2 + O(m)$$$.

Similarly to $$$f(i, j)$$$ in the editorial we can define $$$g(i, j, l)$$$ as a sequence of operations that performs xor-assignments $$$a_i = a_i \oplus a_{j+l-1}$$$, $$$a_{i+1} = a_{i+1} \oplus a_{j+l-2}$$$, ..., $$$a_{i+l-1} = a_{i+l-1} \oplus a_{j}$$$, where indices are cyclic modulo $$$n$$$ and cyclic segments $$$[i, i + l - 1]$$$ and $$$[j, j + l - 1]$$$ do not intersect. This sequence is the same as $$$f(i, j + l)$$$ when $$$l \equiv j - i$$$ and otherwise ends with 3 passes between $$$i + l - 1$$$ and $$$j$$$ to clean up the mess. Defining $$$h(i, j, l)$$$ as a sequence of operations that reverse-swaps such two segments, $$$h(i, j, l) = g(i, j, l) \mathbin\Vert g(j, i, l) \mathbin\Vert g(i, j, l)$$$, $$$\frac{3}{2} m^2$$$ solution is $$$h(0, \lceil\frac{n}{2}\rceil, \lfloor\frac{n}{2}\rfloor)$$$.

But we don't have to drag $$$a_{n-1}$$$ through the whole array to get to $$$a_0$$$. Essentially instead of $$$swap(a_0, a_{n-1})$$$ we can perform $$$swap(a_{n-1}, a_0)$$$, then we replace two long passes and one short with two short passes and one long. Instead of $$$h(0, \lceil\frac{n}{2}\rceil, \lfloor\frac{n}{2}\rfloor)$$$ we split both segments, reverse-swap one pair though the middle of the array and the other through the ends. For example, taking $$$x = \lfloor\frac{n}{2}\rfloor$$$, $$$y = \lceil\frac{x}{2}\rceil$$$: $$$h(n - y, 0, y) \mathbin\Vert h(y, n - x, x - y)$$$.

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

Hint 2 for problme D: Combined with the first hint, we can say that a triplet (a,b,d) has no solutions if min(lsb(a),lsb(b))<lsb(d). Here, lsb(x) represents the least significant bit of x.

Does this mean that if a and b are even and d is odd then it should have no solution but test case 7 of the example have a solution?

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

    Does this mean that if a and b are even and d is odd then it should have no solution It's incorrect. There is a solution.

    If $$$a$$$ and $$$b$$$ are even, then their LSB of both are greater than 1.

    If $$$d$$$ is odd, then its LSB is 1.

    $$$min(1, 1) \lt 1$$$ Isn't true. Hence, there is a solution.

    If you are confused with the fact that if $$$min(lsb(a), lsb(b)) \lt lsb(d)$$$, then there is no solution., read below.

    Let $$$dq$$$ be any multiple of $$$d$$$. And $$$k = lsb(d)$$$. You can see that $$$lsb(dq) \geq lsb(d)$$$. It can be easily seen by adding d itself in its binary representation. You can see that any multiple of $$$d$$$ will have its bits on after or from $$$lsb(d)$$$.

    Let $$$m = a|x$$$. According to the problem, we require $$$m$$$ to be some multiple of $$$d$$$. Since $$$m$$$ will be forced to have on all bits that are on in $$$a$$$ or $$$x$$$, then $$$m$$$ will have the $$$lsb(a)$$$ bit on. But we have seen that any multiple of $$$d$$$ will have its bits on from or after its lsb. Hence, if $$$lsb(a) \lt lsb(d)$$$, then there is no solution, it's impossible to have any multiple of $$$d$$$ that can have the $$$lsb(a)$$$ on, since it's less than $$$lsb(d)$$$.

    So if $$$lsb(a) \lt lsb(d)$$$ or $$$lsb(b) \lt lsb(d)$$$, then there is no solution.

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

I use unordered_map in C, and I get TLE.

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

I keep getting a "wrong" judgement on my Kotlin code even though I followed the example solution to a tee. Any hints?

import kotlin.math.max
import kotlin.math.min

fun main() {
    val t = readLine()!!.toInt()
    (1..t).forEach {
        readLine()
        val s = readLine()!!

        var result = 0L

        (0..s.length-1).forEach outer@ { fro ->
            // count how often each digit 0..9 has occurred so far
            val numOccur = MutableList(10) { 0 }

            // only substrings of length <= 100 can be diverse, otherwise maxOccur >= 11 is forced
            val maxTo = min(fro+1 + 100, s.length)
            var diversity = 0
            var maxOccur = 0

            (fro+1..maxTo).forEach inner@ { to ->
                val idx = s[to - 1] - '0'
                numOccur[idx] += 1

                // no matter what chars we add, it can never be diverse anymore
                // note that this also makes the above length-100 condition obsolete
                if (numOccur[idx] > 10)
                    return@inner

                diversity += if (numOccur[idx] == 1) 1 else 0
                maxOccur = max(maxOccur, numOccur[idx])

                result += if (diversity >= maxOccur) 1 else 0
            }
        }
        println(result)
    }
}
»
3 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

I'm not sure I'm right or not, but const number can't exist in $$$O()$$$(except $$$1$$$).

The number of operations are $$$n\times10^2$$$ but you can't say that the time complexity is $$$O(n\times10^2)$$$,maybe.

And of course it is easy to understand, but I suggest to fix it due to rigour.

If I'm wrong please figure out thx.

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

    I think $$$O(N \cdot 10^2)$$$ is more concise than saying "$$$O(N \cdot a^2)$$$, where $$$a=10$$$ is the alphabet size", even though it's not as rigorous.

    Nice observation though!

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

    me when worst case $$$n$$$ is worst case $$$10^5$$$ so my $$$O(n^3)$$$ solution becomes $$$O((10^5)^3)$$$ which is a constant so it is equal to $$$O(1)$$$ so it enters any conceivable TL

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

I finally became Master after this round. Thank you for the interesting problems.

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

I feel like there's an error in editorial of problem C. It should be added $$$[s_{i_1}, s_{i_1 + 1}, \cdots, s_{i_2 - 1}]$$$ in between $$$[s_1, s_2, \cdots, s_{i_1 - 1}]$$$ and $$$[s_{i_2}, s_{i_2 + 1}, \cdots, s_{i_3 - 1}]$$$. Of course, it does not really matter, the pattern is obvious, I was just pointing it out.

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

I have a stupid and complicated solution for B https://mirror.codeforces.com/contest/1748/submission/180642025 time complexity O(n logn)

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

I think the sample of D is a big hint. During the competition, I tried to convert the output of the last example into binary and found that the last 30 digits are all 1s, so I could find the solution. I think if the sample set the last 30 digits to be a|b, I must not be able to solve it.

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

how to solve d with exgcd(Extended Euclidean algorithm)?

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

Have someone else solved C by dp?

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

    tried but wa if you know pls teach me

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

      Consider $$$O(n^2)$$$ dp: $$$dp(i)$$$ -- maximum number of consecutive subsegments with zero sum you can get from the $$$i$$$-th prefix. $$$dp(i) = max_{j = 1...i} check(j, i) * dp(j - 1) + 1$$$ where function $$$check(l, r)$$$ is a boolean function which returns $$$1$$$ if you could obtain subsegment $$$(l, r)$$$ having zero sum. It is possible if and only if it contains $$$0$$$ or if it has zero sum. You can consider these two cases and optimize dp: find previous zero left to position $$$i$$$ and get something like prefix minimum, and for second case you can store in map optimum dp for every prefix sum value.

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

so my question is:

why https://mirror.codeforces.com/contest/1748/submission/180728658 this works and https://mirror.codeforces.com/contest/1748/submission/180728780 does not?

the only difference is that in #1 I go from n-1 to 0 and #2 I go from 0 to n-1

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

This's a great round... and my first round in CF :)

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

can someone explain the dp solution for qC?

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

Can anyone explain why in problem "C — Zero Sum Prefixes" is c++ std::map (my test) more preferable than std::unordered_map (my time limit test)?

Always thought that std::unordered_map should give constant time on all required operations but std::map — logarithmic. sorry for the newbie question.

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

I participated from an alt but wanted to offer my feedback on the problems.

A — alright, I accidentally saw the title before I vc'd and prewrote the code, it actually worked

B — also alright

C — not very interesting, this problem does not need to exist

D — weird definition of an integer, this problem does not need to exist

E — annoying, this problem does not need to exist

F — incredibly annoying, I don't like this problem at all, i won't even try to solve it

Am o problema mai calitativa:

Dandu se un sir de operanzi cifre si operator ^ * | & ~ XOR + — / ** ! oplus, gasiti valoarea maxima a expresiei facand maximum k interschimbari.

Marinush

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

I participated from an alt but wanted to offer my feedback on the problems. A — alright, I accidentally saw the title before I vc'd and prewrote the code, it actually worked B — also alright C — not very interesting, this problem does not need to exist D — weird definition of an integer, this problem does not need to exist E — annoying, this problem does not need to exist F — incredibly annoying, I don't like this problem at all, i won't even try to solve it I have another solution for F: Bagi bulaneala pe vectori

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

For problem D, how can we say for sure that $$$x$$$ will be of the form: $$$p11..11(30 - k \ times)00..00(k \ times)$$$

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

In problem D: How can we prove that $$$x_{(2)}=p 1 1 1 … 1 0 0 … 0$$$ is divisible by both a and b? Please, help!

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

The data structure, described in the editorial for problem E, is called Cartesian tree. One can build it in O(N).

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

How come in Problem B, not using ~~~~~ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ~~~~~ gives AC 181109995 but using this in code gives WA 181109865

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

I came up with a different solution to problem E but it is not working (even on the first test case). I can't figure out what is wrong with my approach. I have described the idea below.

Observation

a[i] >= a[i + 1] implies b[i] >= b[i + 1]

a[i] < a[i + 1] implies b[i] < b[i + 1]

dp state: dp[i][j] = number of arrays with b[i] = j

// base case
for j: 1 ... m
    dp[1][j] = 1;

// transition
for i: 2 ... n
    for j: 1 ... m
        if(a[i - 1] >= a[i]) // then b[i - 1] must be greater than j as per observation
            for k: j ... m
                dp[i][j] += dp[i - 1][k]
        else
            for k: 1 ... j - 1 // then b[i - 1] must be lesser than j as per observation
                dp[i][j] += dp[i - 1][k]

Below is a link to my submission with actual code (which optimizes the above pseudocode using a prefix sum array.

181409754

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

In problem D, there's this step in the explanation

$$$p+1 ≡ (2^{−1})^{30−k} \mod d' ⇔ p+1 ≡ (\frac{d'+1}{2}) ^ {30−k} \mod d'$$$

I don't understand where it comes from, like what property is being used or why this is done, can anybody help me please?

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

Why is my same code getting accepted in GNU G++17 7.3.0 and not in GNU G++20 11.2.0 (64 bit, winlibs) ? What's the difference between these two languages? GNU G++17 7.3.0 — 186674226 GNU G++20 11.2.0 (64 bit, winlibs) — 186674279

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

For problem B, can anyone help me understand why this 188673953 is AC, but this 188673213 is WA?

The AC one is simply starting from ans=0 and doing ans++ for each diverse substring. The WA one is the opposite. It starts with ans=(n*(n+1))/2 and doing ans-- for each non-diverse substring.

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

    Take a look at Ticket 16693 from CF Stress for a counter example.

    By the way, it's trivial to prove that your WA algorithm is incorrect. In your AC submission, you are iterating over all diverse substrings. In your WA submission, you iterate over all non-diverse substrings. So if I combine both of your solutions, I would be able to iterate over all $$$O(n^2)$$$ substrings in $$$O(n)$$$ time. A contradiction.

    The catch here is that the diverse substrings are scarce, and closer to $$$O(n)$$$, while their complement is abundant, of order $$$O(n^2)$$$. That's why the subtraction strategy would result in TLE if implemented properly, or would undercount the non diverse substrings of length greater than 100 if implemented poorly.

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

In C can it happen that maximum frequency prefix of the subarray is such that for nullifying that prefix our ai exeeds the limit of 1e9 ?

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

D is such a nice problem man but there is something that I found very unintuitive about it and that is — why you filled all the digits before p and after k to be one. I mean the best thing I could arrive at after solving this problem for hours was that rather than filling up all of them with ones as you did I would fill it with a^b and I reched nowhere.

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

Is there a flow-based solution for Problem E?

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

might be stupid to ask but how we can write

inverse_of_2=(d+1)/2;

any proof or just observation?