Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

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

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

Thanks for participating in Codeforces Round 1122 (Div. 3)!

Rate the contest!

2266A - Good Contest

Hint
Solution
Code (C++)
Rate the problem!

2266B - Three Piles

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

2266C - AND, OR, Sort!

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

2266D - Falling Concrete

Hint 1
Hint 2
Solution
Code (C++)
Rate the problem!

2266E - Prime Destruction

Hint
Solution
Bonus
Code (C++)
Rate the problem!

2266F - MEX Replacement

Hint 1
Hint 2
Hint 3
Solution
Bonus
Bonus Answer
Code (C++)
Rate the problem!

2266G - Modular Tree

Hint 1
Hint 2
Hint 3
Solution
Code (C++)
Rate the problem!

2266H - Deque Malfunction

Hint 1
Hint 2
Hint 3
Hint 4
Solution
Implementation 1: Lazy Segment Tree
Code (Lazy Segment Tree)
Implementation 2: Amortized Set Deletion
Code (Amortized Set Deletion)
Rate the problem!
Разбор задач Codeforces Round 1122 (Div. 3)
  • Проголосовать: нравится
  • +98
  • Проголосовать: не нравится

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

Update the announcement :3

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

all the code sections are empty. are you waiting until after the hacking, or is this a mistake?

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

Sigma round, loved so much. But not C >:(

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

For H, instead of a segtree, we can use a BIT for easier implementation: https://codeforces.me/contest/2266/submission/391534225 Finding maximum over (t,m] is the same as finding maximum on (0,m-t]

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

had a ton of fun solving F :D, my bound for the binary search was [0,n+60] which makes it a bit easier to implement than having it bound by mx, and it's pretty easy to prove. was scared I didn't handle the overflow well but I guess it was just 1 if lol

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

    I solved F after the contest but used the bounds [mxValue -> (mxValue + 32)]. Just iterate over this range and get the result. My proof is : if I want the answer to be mx + i then I need all the values in range [0-mxValue] to have frequency atleast (1 << (i - 1)). And as the max frequency is 1e9 so answer will not be greater than mxValue + log2(1e9)

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

I can’t remember the last time a Div 3 contest rekt me this hard.
After looking at the editorial, I actually like this contest.

Also, my post contest discussion stream here. ABCEDFG is the order.

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

D and E had me STRESSED. Glad I succeeded in solving them, and props to you WorldWarV for this contest! The problems I managed to solve had very elegant solutions, which I appreciate.

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

I solved C using dp

Submission

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

    Likewise

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

    Can u explain the logic?

    • »
      »
      »
      6 недель назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится
      1. Notice that s1 can never change (As s[i] = (bitwise | or &) of s[1], s[2], ... s[i]) (Put i = 1 in that equation to prove it)

      2. We want the string to be sorted in non-dec order so we know that if s[i - 1] was 0, then s[i] can be both 0 or 1 (both possibilities) whereas if s[i - 1] was 1, then s[i] must equal 1 (if s[i] = 0, then it becomes unsorted, defeating our purpose)

      3. We will go step by step trying all possibilities through recursion

      Code

      We will try to go through ALL POSSIBILITIES and find the minimum operations out of them.

      Then memoize it (just store the values of the already calculated function calls so that we can save time).

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

I solved E after the contest. I didn't use DP I brute-forced the solution for each number in the array by factorizing it, and then found the formula for how many operations it will cost if I want to remove factor x from ai

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

    could you please explain your approach I want to know

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

      Let a be some number that we want to reduce such that a <= k

      One operation allows us to remove a prime number from a

      We know that any number is the product of some prime numbers.

      So assume a = p1 * p2 * p3 * p4 * p5

      Let's say that we choose to remove p1,p2,p3 from a because we know that p4 * p5 <= k

      Now all we need to know is the number of operations required to make a and all the numbers it produced equal to p4 * p5

      We start with a which is (p1 * p2 * p3 * p4 * p5)

      We divide it by p1 and now we have p1 instances of (p2*p3*p4*p5) and cost+=1

      Now we divide each one of these new instances by p2 and we end up with p1 * p2 instances and cost+=p1

      Now we also divide these p1 * p2 instances by p3, and we end up with p1 *p2 *p3 instances and cost+=p1*p2

      So in order to remove p1, p2, and p3, it cost us 1 + p1 + p1*p2.

      So I first precomputed these costs for all numbers from 1 to 2e5 and then I tried all valid possible subsets of primes to remove

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

I looked at H a bit differently, i.e. fix the start position and optimizing for the number of prefix maximums and prefix minimums.

Since these two sequences are independent excluding the starting element, we can optimize them individually.

For the prefix maximum case, if we want to add a value at position $$$j$$$ to the sequence ending at position $$$i$$$, we need to ensure that all values in $$$[b_i + 1, b_j - 1]$$$ is in $$$b[j + 1, n]$$$.

That way we can propagate from $$$j$$$ to $$$i$$$ by considering the minimum $$$b_i$$$ to be the first value not appearing in $$$b[j, n]$$$ that were less than $$$b_j$$$.

The same method can be used for the prefix minimum case.

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

Problems with easier implementations but harder ideas are so orz, one of my favorite contests so far

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

Nice round! Problem E was definitely easier than D if you know prime factors

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

Dealing with bigness of numbers in F was such a headache for me :(

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

A-B very easy

C standard prefix

D This felt very hard, All i could think of was sort with A[i]-i but couldn't do anything beyond it

E Easy dp with sieve

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

This was my first contest, I want to know when the rating update happens??

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

C can also be modelled using easy dp

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

Great Contest.Bob and Alice fought again BTW

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

Auto comment: topic has been updated by WorldWarV (previous revision, new revision, compare).

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

Well, solved till 5th question

Confortable till 4th though Thinking spf and reccursiveness was the coolest part

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

hell C

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

I solved C using dp :) 391473244

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

E was a good problem:)

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

If i were to be honest, the difficulty curve of the problems were kinda inconsistent, for example i would personally say that D was harder than E but that might just be my skill issue. (Also the tutorial for d is somewhat vague too) Overall it was a great contest tho!

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

Felt more like a div 2 than a div 3, of course problem D and E would be easier than div 2, but first 3 weren't really easier.

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

Here is my $$$O(n^\frac{4}{3} \log{n})$$$ solution for Bonus E.

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

D got AC during contest but shows TLE now :(

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

Very good contest

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

Can anyone explain the solution of problem G in easy terms and words?

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

My rough solution for Bonus E.

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

Bonus for problem F

Idea come from bitwise,assume that input range x $$$\in [0,n)$$$ and every number with frequencey $$$10^9$$$,i define $$$n$$$ as position $$$0$$$,$$$n+1$$$ as position $$$1$$$ and so on,$$$n+i$$$ equal to position $$$i$$$,now i observe something interesting if you regard the reverse binary representation as a decimal number then the decimal number is the number of times for the x $$$\in [0,n)$$$ need to deduce to form,for example,if look like "011" the reverse is "110" which is $$$6$$$,so you need $$$6$$$ times to get number $$$n+1$$$ and $$$n+2$$$ the proof is simple,if we let any number $$$x\lt n$$$ reduce $$$1$$$ then the number of position $$$0$$$ will increase $$$1$$$,this act like a binary adding operation.

So let the maximum number be $$$n+k-1$$$ then $$$1+2^1+2^2+..+2^k=2\cdot 10^{14}$$$,thus $$$k\approx 48$$$,why $$$2\cdot 10^{14}$$$?because every number greater than $$$n+50$$$ is useless and we can make them into $$$0$$$ so this is a approximation,in real situation it can't reach

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

Explanation for G AC code

What you need?:$$$\text{Bezout indentity,dfs,gcd}$$$

  1. First we reduce the problem,i don't know how to construct the answer then i let $$$y_i$$$ is the maximum number $$$x_i$$$ can reach,then $$$ans=\sum y_i$$$ .

  2. Now,i observe something interesting,$$$y_i$$$ is independent,why?Let $$$u$$$ be the parent of $$$v$$$,then i can make $$$x_u$$$ to $$$y_u$$$ first,then after that no matter how i change $$$x_v$$$,it won't affect $$$x_u=y_u$$$

  3. from step $$$2$$$,the problem reduce to how to maximum $$$x_i$$$ to $$$y_i$$$,now i suddenly observe something,let set $$$A=\{s_v\}$$$ which $$$s_v=\sum x_v$$$ for some moment,obviously $$$|A|$$$ (size of the set) is finite,then the $$$(x_i=a_i + c_0\cdot b_i + c_1\cdot s_1 + ... )\mod b_i$$$,if you see this form you must be sensitive,because this is related to the general bezout identity,define $$$g=\gcd(b_i,s_v)$$$ then you can see that no matter i reduce how many times of $$$b_i$$$ or increase how many times of $$$s_v$$$ ,in the kernel ,always increase/decrease some $$$g$$$ and bezout identity state that i always exist such a set of coefficient such that $$$(c_0\cdot b_i + c_1\cdot s_1 + ... )=g\mod b_i$$$,for example if $$$s_1=10\cdot g$$$ and $$$b=20\cdot g$$$ then if i increase $$$1$$$ time $$$s_1$$$ and decrease $$$1$$$ time $$$b$$$ then result is $$$+10\cdot g - 20\cdot g=-10\cdot g$$$,in modular i can use add arithmetic to simulate minus arithmetic,for example if $$$b=20\cdot g$$$ and current $$$x_i$$$ be $$$constant+10\cdot g$$$,if i want minus $$$3\cdot g$$$,i can directly add $$$17\cdot g$$$

  4. Now everything is almost clear,$$$x_i=a_i + k\cdot g$$$ and $$$k$$$ is some constant,i observe that if $$$a_i\ge k$$$ then $$$a_i$$$ also produce some of the $$$k$$$,thus let $$$r_i = (a_i \mod g)$$$ then $$$x_i = (r_i+c\cdot g)\mod b_i$$$ and $$$c$$$ is some constant,how to maximize this equation?Remember that $$$b_i$$$ is a multiple of $$$g$$$ thus let $$$b'=\frac{b}{g}$$$ then apparently $$$c\ge b'$$$ is useless it will cycle back,so we can ensure that $$$0\le c\lt b$$$ then i greedily pick the largest one and i found that $$$r_i+(b'-1)\cdot g=r_i+b-g\lt b_i$$$,so we can conclude that for every vertex $$$i$$$ the maximum $$$x_i$$$ it can reach is $$$r_i+b-g_i$$$ and $$$r_i=a_i \mod b_i$$$ and $$$g_i=\gcd(b_i,s_v)$$$

  5. How to construct answer?Actually we don't need $$$s_v$$$,we need $$$g_v$$$,Define $$$u$$$ as the parent of $$$v$$$ then $$$s=\sum a_v$$$,let me remind you what $$$g_i$$$ meaning for,$$$g_i$$$ is the change of every operation in $$$x_i$$$,in other word $$$x_i$$$ always increase/decrease $$$g_i$$$,so we can say that for $$$s_v$$$ of $$$u$$$ , we have $$$s_v=s+\sum c_v\cdot g_v$$$ and $$$c_v$$$ is some constant,tell me what's this form?Bezout identity right?So let $$$g_i=\gcd(b,s,g_v)$$$ then no matter i increase how many times of $$$b,s,g_v$$$ the kernel is i always increase/decrease $$$x_i$$$ some $$$g_i$$$

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

More clean Max-segment tree solution for H AC code

You can learn from author : Al.Cash

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

I took a different perspective on H: it can be seen as a longest increasing/decreasing subsequence variant. Looking just at the low value side: observe that for a given value $$$b_i$$$, we can only ever avoid a malfunction if $$$1,2,\cdots, b_i-1$$$ are all present in $$$b$$$ at positions $$$ \gt i$$$; filter out all items for which this doesn't hold. On the remaining items, observe that a decreasing subsequence of length $$$k$$$ with first chosen value $$$v$$$ corresponds to insertions on the left side going from $$$v$$$ to $$$1$$$: for any un-selected element we have it malfunction at its last possible time, and our filtration rule guarantees we will be able to do this. The standard LIS approach going backwards over $$$b$$$ gives the full tradeoff frontier between $$$v$$$ and $$$k$$$; combine this with the mirrored high-value solution to find an optimal cutoff starting value. Note that this approach also makes it easy to explicitly construct the optimal series of choices.

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

D was really witty question!!

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

I have a doubt in problem E where in the given testcase where

12 3 12 10 9 8 7 6 5 4 3 2 1 12

here I think we can do it 12 operations because if we select our final multiset elements to be {1, 2, 4} then 12 : p=3 x/p=4 -> 1 ops 12 : p=3 x/p=4 -> 1 ops 10 : p=5 x/p=2 -> 1 ops 9 : p=3 x/p=3 each p=x/p=3 x/p=1 -> 4 ops 8 : p=2 x/p=4 -> 1 ops 7 : p=7 x/p=1 -> 1 ops 6 : p=3 x/p=2 -> 1 ops 5 : p=5 x/p=1 -> 1 ops 3 : p=3 x/p=1 -> 1 ops

so the minimum operation is 12 but in the test case it is mentioned as 15. please correct me if I am doing wrong somewhere

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

    You need to use prime divisor,for example your change of $$$12$$$ is $$$12\rightarrow 4 \rightarrow 1$$$ but you can't make $$$4$$$ to $$$1$$$ in one step because $$$4$$$ is not prime divisor

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

learnt something new from D and E after a long enough hiatus from CF, thanks

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

G is clever, love it :D

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

The pre() function has an unnecessary line, cmp[i] = true. Since the outer loop never revisits i, marking the current index doesn't affect the result. The important marking is cmp[j] = true, which allows composite numbers to be skipped in later iterations. I also found it a bit counterintuitive to mark every i as cmp, even when i is prime.

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

I solved C using kadane's algorithm sort of approach (it can be applied to this if the first element is '0') check it out here — (https://codeforces.me/contest/2266/submission/396782062)

the approach is basically like... the first part of the string should surely be 0s (unless first element is 1), so traverse the string and increment sum when 0 is encountered and decrement it when 1 is encountered and keep track of maxSum and index at which maxSum occurred as well.. that index will be the position until zeros will appear in the sorted string after which ones will appear...