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

Автор cry, 2 года назад, По-английски

1996A - Legs

Problem Credits: cry
Analysis: cry

Solution
Code (C++)

1996B - Scale

Problem Credits: sum
Analysis: cry

Solution
Code (C++)

1996C - Sort

Problem Credits: cry
Analysis: cry

Solution
Code (C++)

1996D - Fun

Problem Credits: sum
Analysis: cry

Solution
Code (C++)

1996E - Decode

Problem Credits: cry
Analysis: cry

Solution
Code 1 (C++)
Code 2 (A Little Different) (C++)

1996F - Bomb

Problem Credits: sum
Analysis: cry

Solution
Code 1 (C++)
Code 2 (C++)

1996G - Penacony

Problem Credits: cry
Analysis: cry, awesomeguy856

Solution - Segment Tree
Code (C++)
Solution - XOR Hashing (by awesomeguy856)
Code (C++)
Разбор задач Codeforces Round 962 (Div. 3)
  • Проголосовать: нравится
  • +110
  • Проголосовать: не нравится

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

cry orz

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

Couldn't solve D. RIP my brute force skill.

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

After reading problem F You realize that nuclear bombs take so much time to bomb!

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

G reminds me of this JOISC problem

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

In problem F: We are searching for the largest x such that f(x)≤k

Won't we reach infinity by doing that?

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

My solution for problem F:

let's find the minimum number X, where X is the smallest number that all numbers in array a can be less or equal than using at most k operations.

then, you calculate the answer for making all the numbers in a less than X, and maintain values k and a[i] for each i.

After all you will be left with k operations, so you add to the answer : number_in_a_equal_X * k

link to my solution

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

Amazing xor-hashing solution for G, love it!

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

great contest, really fun problems. i wish i managed to solve E on time as well but oh well

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

Can anybody tell why this solution for C is getting MLE?

Submission

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

please can anyone explain why my code works or if it can get hacked please hack it : ), i will be so happy (https://codeforces.me/contest/1996/submission/272827778)

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

Can anyone explain how this code works? I don't understand it. Also, can you provide some sources that explain how it works? Thanks! 272756177

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

cry sum Is there a penalty on unsuccessful hacking attempt?

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

Thank you for the editorial ! There is just a little typo in the explanation of problem E. You wrote in the line before the last one $$$(x+1) \cdot ((n-y_1+1) + (n-y_2+2) + ... + (n-y_k+1))$$$. It shouldn't be $$$n-y_2+2$$$ but $$$n-y_2+1$$$

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

O(n) solution of D :

wlog assume a <= b <= c

claim : atleast a, b <= √n

proof : if b > √n, b * c >= b * b > n which proves the claim so iterate on a and b till √n and count the permutations, this can be done in many ways

submission

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

Why will the "remaining operations will all add (x — 1)" in the solution for F?

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

    We know that there must be at least one element that is x-1, because otherwise it's clearly not the smallest x. Then, if there are less (x-1)'s than there are operations left, you could perform operations on those elements, and thus this not the smallest x. But if there were more (x-1)'s than operations left, then the they would all be (x-1).

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

    Let us note that $$$f(x - 1) - f(x)$$$ will mean how many element can start from $$$x - 1$$$ [check the last paragraph], because an increase in count between consecutive arguments can only occur if the smaller one is having some elements start for that argument,

    If x is the smallest value for which our $$$f(x)$$$ is $$$\leq k$$$, means $$$f(x - 1) \gt k$$$. This means that $$$f(x - 1) - f(x)$$$ number of elements have started from $$$x - 1$$$. We have $$$k - f(x) \lt f(x - 1) - f(x)$$$. Therefore the number of elements which will start from $$$x - 1$$$ is larger than the leftover operations.

    By elements starting from a number, I mean lets say $$$a_i$$$ = 7 and $$$b_i$$$ = 4, and $$$x$$$ = 4, then the AP of elements we can pull from this index is 7. Hence this element "starts from" 7. Also, within this example, consider what happens when $$$x$$$ = 3 (instead of 4), the AP of elements we pull is 7, 3. There is an increase in count from 1 to pulling 2 elements, and this change occurred because an element started from 3, (this 3 will not be pulled from this index if our $$$x$$$ is 4, but it will be ready to be pulled from the leftover operations).

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

can anyone please explain me the editorial of Problem D "Since ab+ac+bc≤n , we know at the minimum, ab≤n . " or is their any other approach please share

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

Anyone tried G with greedy then use segment tree? Like sort or pair by ascending order of min(b-a, n+a-b), assume a<b, then tried to input range [a,b] or [b,n],[1,a] to find which one is minimum. I do not know whether is works, as I tried sometimes but fail

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

Would a Randomizing Approach work for G? If you choose which edge to be deleted first there will be only one path which makes it clear which edges to remove after. Would randomly choosing the first edge to be deleted solve the problem (Assuming you only randomly choose from valid edges to be removed)? Too lazy to try coding it.

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

in D, it is mentioned in the problem statement that the triplet (a, b, c) are positive numbers, i.e., > 0.

Given ab+bc+ca <= n, at minimum, ab+b+a <= n should be true, since c>=1 Which impliesb <= (n-a)/(a+1), instead of n/a as mentioned in the editorial.

When I apply these constraints, I get WA on test 2 for an unknown test case. Can someone please explain where I am going wrong ???

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

Can someone please explain why in problem 1996F - Bomb we need to add exactly (v*(k-all_ops)). In tutorials they just go through it and they don't even explain. I always trying to understand by myself till i'm done but its first time when im asking help(i watched all possible tutorials). My code 272878301 .

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

Why is this code not working?

为什么这段代码不起作用?

Почему этот код не работает?

このコードが機能しないのはなぜですか?

272886072

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

非常难

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

Now i can't solve D just because i was thinking too complex... That's funny while I can solve E

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

F is equivalent to aliens' trick (A.K.A. wqs's binary search algorithm), for the functions mapping k (the number of operations) to answer (the maximum of sum selected by k operations) is convex.

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

Problem D provides an O(n) solution where no two numbers in a,b, or c are simultaneously greater than the square root of n, so the two square roots traverse a,b, find c, and then remove the duplicates.

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

For problem G there is an interesting property that if two edges (e.g. $$$(a,b)$$$ and $$$(c,d)$$$) cut with each other, they must connect to each other $$$(a,b,c,d)$$$. So finally we will reach a partition of a circle (here I indicate a partition of a circle means that there do not exist two edges which cut with each other in two complete maps of point sets), and we can find the answer quickly by some simple method.

The problem is how to find the partition of the circle. First, we sort the edges, and then we need to perform a stack of sets which indicates that all the points in a set needs to be connected. We can easily find whether an edge cuts an edge of a set. To lower the time complexity, you will find if we pile the stack by the time we build it, if the edge cuts with one set, all the sets which on the top of this set must cut with this edge. Then just merge the sets by size. The total time complexity is $$$O(n \log n)$$$.

I must mention that I haven't implement this, but I think it is an interesting approach of this problem.

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

    I am not sure if i not getting right what you are saying or your statement is false

    here's example for n=15, and 3 edges(1-4,3-6,5-15) according to your statement it should be connected by(1-3-4-5-6-15) but that would not be optimal solution(it should be 15-1-3-4-5-6).

    correct me if i am wrong.

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

      It's my bad not make it clear that I mean the points in a set means they should be connected by one path.

      In your example, for the edges $$$1-4, 3-6, 5-15$$$, they cut with each other, so they must be connected in a path. Both path $$$1-3-4-5-6-15$$$ and $$$15-1-3-4-5-6$$$ let them connected.

      If you still don't understand, you can see that if $$$(a,b)$$$ and $$$(c,d)$$$ cuts, we can add $$$(a,c)$$$, $$$(a,d)$$$, $$$(b,c)$$$, $$$(b,d)$$$ four edges and this does not change the answer, and that is what I mean "they must connect to each other". $$$(a,b,c,d)$$$ can be connected in many ways, like $$$a-b-c-d$$$ or $$$c-d-a-b$$$, but they must be connect by one path.

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

can anyone help why is this TLE ? problem 1996F - Bomb

Code

I literally cannot imagine edge case, feels like it should work logically

the idea is basically take the max of a[i] until it becomes smaller than second largest a[i] (if it exists)

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

    Your code will TLE in the case like this:

    Hack

    Where $$$n \ge 2$$$, and $$$k$$$ is sth very large.

    We have to compress these steps use binary search, then the rest "useful" operation will be at most $$$n$$$.

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

My thought process for C and D for newbies like me...

C

  • (obs) if we find the positions where the two sorted ranges differ we would be done
  • it was evident by the number of queries and input range that precomputation is required
  • but precomputation of where the two strings differ only if we don't have to sort each range...
  • (obs from examples) no need of sorting range, we just have to find that in the range which characters are extra in a
  • so precompute frequencies of all characters in the ranges:)
  • a hint could have been that it was mentioned only small latin chars

    D

  • (obs1): think of what the bounds on values of a,b and c are(makes sense as we need to find the count of possible tuples)
  • a,b and c can lie between 1 and min((n-1)/2, x-2) => O(max(n,x)^3) solution possible
  • (obs2): if we just iterate over a and b then number of tuples for given pair will be possible values of c and for this setup c is btw 1 and min(n-(ab)/(a+b),x-(a+b)) => O(max(n,x)^2)
  • (obs3 (which I missed in contest)) => ab is less than n so that gives us a bound on values of b too.(well this should have been obvious as otherwise why would we be given 2 inequalities one was enough for square complexity)
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Didn't understand G's train of thought

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

    Here is the explantion of the solution with segment tree.

    So first we have a cycle of $$$N$$$ nodes.

    Then, it is obvious that when we force to delete an edge, this cycle will become a chain which can be assumed to be an array.

    And we just enumerate the edge we force to delete, then use sth fast to calculate the answer of the unique way to maintain the roads.

    And to do this, a segment tree is enough.

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

In problem F, I want to use slow solution for these remaining operations but get TLE on test 10. May I ask if there is any problem with this code?(https://codeforces.me/contest/1996/submission/272913613)

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

在G题里面,为什么这样的维护道路方案是有效的? 我觉得sort道路长度的顺序应该也是可以的感觉

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

Problem E: why we have x+1 options as l? I think l should be in a range from 1 to x, then it's x , not x+1

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

I have no idea how I'm getting a TLE from B. It was initially accepted, but it just got a TLE during the system testing phase. My solution looks similar to the one in the editorial, is there anything that I'm missing?

My submission

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

Bruteforces

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

Thanks!

Great tutorial and problem idea for G

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

D can also be done in a sort of O(n) complexity .

my approach was to deal with any 2 or more are equal in a separate case and all three distinct in a second case

well any 2 or more equal can easily be thought of in O(n) but for all three distinct without loss of generality

let's consider a>b>c

this means ab> c*c , bc > c*c and ac > c*c .

thus 3 * c*c < ab+bc+ac <= n

thus c can take a maximum value till sqrt(n/3) thus we can iterate over it's possible values in o(sqrt(n))

note : one must check if x is less than this sqrt(n) to get a faster code

now having fixed c let's think of b

ab > b*b , ac > bc thus , b*b + 2bc < n

now for each value of c we get an upper bound of b that can be calculated to be of the order of O(sqrt(n)) having fixed any 2 it's easy to calculate the number of possibilites for a

now since we are nesting 2 loops over O(sqrt(n)) the overall complexity would be O(sqrt(n) *sqrt(n))ie O(n)

My implementation : 272824868

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

Was G a standard problem? Can anyone share the standard problem or resource to learn about the idea if it was?

TY in advance.

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

Problem D is such a low quality problem. I got hacked with verdict TLE but after the system testing I submitted same hacked code and got accepted . I was ranked 444(official) before hacked and finished at 2k+ after hacked . And lost my opportunity to be expert.

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

    All solutions at 19xx/2000ms? No, not a chance that the problem had a bad TL. You were having a suboptimal solution.

    $$$\mathcal{O}(n \log^2 n)$$$ time complexity is a very gray zone at $$$n \le 10^6$$$, and in most cases it should have been TLE'd long ago. It was only that this problem involved mostly basic arithmetics and virtually zero memory accesses that the constant factor tipped into your favor (partially).

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

      If I get TLE instantly in my first submission then maybe I could find an optimal solution. Which may guide me to Expert. Actually I am stucked in 1593 max. for a long time. That's why it hurts me a lot

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

F is similar to ABC216E.

The ABC problem is a version of $$$b_i=1$$$.

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

In problem f, how can it be proved that all excess operations over k (s-k) were done with the obtained ok (mid) of the binary search? Specifically how to prove the line, ans -= 1LL * ok * (s — k)

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

Can someone pls elaborate this? Not able to grasp this:

So, it suffices to run the slow solution for these remaining operations (as long as ai>0 ). Alternatively, we can notice that the remaining operations will all add x−1 to our answer (assuming x>0 ).

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

    Suppose f(x)<=k where x is the smallest number, then f(x-1)>k. Now why this is happening,you will be able to see that some value will be equal to x-1 and that will increase f(x-1). Now we have some extra move k-f(x) and for all this extra move we will find some x-1 to add in our final solution.

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

Problem F was nice.

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

How long have you played Honkai: Star Rail? ww

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

Alternate Solution for E.

A pair (l, r) is good if (2*P[l-1]-(l-1) = 2*P[r]-(r)) and the contribution of this pair to the answer is (l*(n-r+1)). So Lets say for a particular l the pairs (l, r1), (l, r2) ... (l, rkl) are good then the answer for this l is $$$\sum_{i=1}^{k} l \cdot (n - r_i + 1)$$$ => $$$k\cdot l\cdot (n+1) - \sum_{i=1}^{k} r_i$$$

So for each L we store the count k and the sum of r's such that (l, r) is good. We can do it easily by traversing the array from right to left.

Submission : 361543456