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

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

Thank you for participation! I hope you liked atleast one problem from the set (:

We tried hard to have an interesting problemset.

It is sad to see people disliking the round only because some problems were hard. Please read the intended solutions to know why we decided to put the problems(especially D) at current positions.

1762A - Divide and Conquer

Idea:satyam343

Hint 1
Hint 2
Hint 3
Solution
Code

1762B - Make Array Good

Idea:satyam343

Hint 1
Hint 2
Hint 3
Solution
Code

1762C - Binary Strings are Fun

Idea:satyam343

Hint 1
Hint 2
Hint 3
Solution
Code

1762D - GCD Queries

Idea:amurto Prepared by:errorgorn

Hint 1
Hint 2
Hint 3
Solution
Code

1762E - Tree Sum

Idea:satyam343 Improved by:TheScrasse

Hint 1
Hint 2
Hint 3
Solution
Code

1762F - Good Pairs

Idea:satyam343

Hint 1
Hint 2
Hint 3
Solution
Code

1762G - Unequal Adjacent Elements

Idea:satyam343

Hint 1
Hint 2
Hint 3
Solution
Code
Разбор задач Codeforces Round 838 (Div. 2)
  • Проголосовать: нравится
  • +240
  • Проголосовать: не нравится

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

Great Round!! Indeed, problems were quite hard but doable, but overall a v.good experience!

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

So I solved the problem D a little differently, I tried to make use of the fact that we can always take multible of some number x > 1 and dump all the other elements in the array and zero will always be multiple,

this give n + n / 2 + n / 4 — = 2n queries in total. There is a lot of case handling but You can look at my code to understand it a little better for e.g. if x == 2, than we can just dump all elements except 0 — 4 — 6 — 8 — 10

now the next smallest multiple we can take is 4 than we have 0 — 8 — 12 -16 If we take zero, than all the elements in gcd(pi, 0) will be different hence we can just use zero or pi that gives largest value

LINK FOR THE SOLUTION : https://mirror.codeforces.com/contest/1762/submission/185393565

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

    The first step to find a not-1 position costs $$$\lfloor \frac{n}{2} \rfloor$$$ querys. The second step cost about $$$n(1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \cdots)$$$ querys. Why the total cost can be limited to $$$2n$$$?

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

      I think we can use a simple idea to deal with the first not-1 position, that is to eliminate not-0 positions as well. You can query (i,i+1), (i,i+2), (i+1,i+2). If they are all ones, you can be sure they are not 0, so remove them from the possible answers, otherwise, you found your first not-1 position. Lmk if I missed anth.

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

        Yeah, as I have done that using vector p2,

        for each i, if gcd(i, i — 1) and gcd(i, i + 1) is 1 than this number can not be 1, reason being,

        x, 0, y, now if zero was in the middle, gcd(x. 0) = x and gcd(0, y) = y so max(x, y) > 1 because distinct elements in permutaion, there is this case where 0 was first or last element and you never find any element in middle just use that as edge case and print 1 n

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

          Also the idea that half of numbers are even can be employed. One can query pairs (1, 2), (3, 4), ... until gcd is 1. If there's no such index encountered we can also query (1, 4) and (1, 3) to finally find the index of a number that is not 1 or that is even. Then we put it at first place and find all gcds of it and with all the other numbers, collect stat and leave only those indices that have the greatest gcd encountered. Repeat until we have two numbers left.

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

          interesting thing is what I did to find first non — 1 position I kept making two queries a= $$$gcd(l,l+1)$$$ and b= $$$gcd(l,l+2)$$$ , then when I find first non — 1 position I put that algorithm , total number of operations is supposed to be $$$2n$$$ right? I don't know why query limit exceeds on test case 26 at first , my theory was if a and b both is 1 I move on else I do the algorithm , later I optimized as if a is not equal to b then I move , that got accepted lol , can you help find out why query limit got exceeded on first logic?

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

    i did exact same apprroach but got WA on test 5 can u please help https://mirror.codeforces.com/contest/1762/submission/185370228

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

    I used a similar approach and stress-tested it on all permutations of size 10, it passed them all. Not sure what the problem is.

    Here is my approach, I maintain a list of possible indexes which are initially all indexes. In each round, I query the gcd of the first element with all other elements. Now the maximum result I get must be the value of the first element and all of its multiples including 0 must give the same value. I repeat rounds till the number of possible elements becomes 1. If the number of elements giving maximum gcd is 1, then my first element must either be a co-prime to all elements with the maximum gcd element being 0, or the first element must be 0. So I answer with the first element and the element giving maximum gcd.

    Submission link Stress test code

    Edit- I found the error thanks to propane. I am exceeding query limit when the first element is 1

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

      i had exactly same approach and for the exceeding query limit when the first element is 1 i used the fact that if for an index on the first 2 queries it got gcd 1 it cant be 0 so i terminated the process there and deleted this index and moved forward but still query limit exceeded came :(

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

    I also came up with this solution! But sadly i couldn't participate in the contest

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

Problem A can use __builtin_ctz(x) for even numbers or __builtin_ctz(x+1) for odd numbers. link: https://mirror.codeforces.com/contest/1762/submission/185402449

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

I really enjoyed this round.

The implementation of the first four problems is quite easy. In this way the problems become purely observational.

Keep up with the good rounds!

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

Intended solution for D is genious.

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

My solution for problem C was a bit different from the editorial. Did that after processing each character I found the number of spaces or free positions where 0/1 may be put that is we have two options for that position. Now we can every time add the 2^spaces to the answer and take respective modulo as well.

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

Can't believe I'm doing this , but alright — I have Idea for D: 1) First we ask n — 1 queries of format ? 1 i, 2 <= i <= n . We will remember all the answers we get

Maximum of all those gcds = a[1], right? Unless all the answers are distinct and are from 1..n-1 — in this case a[1] == 0, and then we can output ! 1 2

Okay, so we know the value of a[1] and we know all the positions j , that gcd(a[1], a[j])==x, for each x

2) Let's take all positions where gcd(a[j], a[1])==a[1] ( we could've remembered this from step 1). For example we have 2, 3, 7 9( it means that a[2] = a[1] * k1, a[3] = a[1] * k2, a[7] = a[1] * k3 ... k[i] is obviously from 0 to (n-1) / a[1]

Now we can just ask another set of questions: ? 2 3 | ? 2 7 | ? 2 9

If any of those gcd(a[2], a[j]) != a[1] then it means either a[2] or a[j] == 0.

As always with guys of green profiles , my code is having WA2 lmao, here it is. Tell me if you can spot a mistake

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

Fast editorial (wtf about #837)

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

Can anyone tell whats wrong with my Submission in D https://mirror.codeforces.com/contest/1762/submission/185370228 it would be great help

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

Very beautiful problem F! I stand up and applause!

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

I solved F with a different approach.

I made a directed graph such that there is an edge from $$$i$$$ and $$$j$$$ if $$$A_i \geq A_j$$$ and all $$$A_k$$$ between $$$A_i$$$ and $$$A_j$$$ are less greater than $$$A_i$$$. Similarly, I add an edge between $$$A_i$$$ and $$$A_i$$$ such that $$$A_i \leq A_j$$$ and all $$$A_k$$$ between $$$A_i$$$ and $$$A_j$$$ are greater than $$$A_i$$$. So, there are atmost $$$2$$$ outgoing edges from each $$$i$$$.

Now, $$$DP_i$$$ = $$$DP_j$$$ + $$$DP_k$$$ — $$$DP_l$$$ where there is a directed edge from $$$i$$$ to $$$j$$$ and $$$i$$$ to $$$k$$$. But to avoid double calculations, we need to subtract $$$DP_l$$$ where $$$l$$$ is the smallest position that can be reached by both $$$i$$$ and $$$j$$$ using some directed edges.

Now, to find this position $$$l$$$, we use binary lifting technique with binary search. Since $$$l$$$ is the smallest position, you have $$$2$$$ nodes $$$u$$$ and $$$v$$$ such that $$$A_u \leq A_v$$$ and $$$A_u \leq A_l \leq A_v$$$. Hence it is always optimal for $$$A_u$$$ to take the edge such that $$$A_{p_u} \geq A_u$$$ and for $$$A_v$$$ to take $$$A_{p_v} \leq A_v$$$.

Now, we can binary search and find the largest node which is less than or equal to mid and check if - they are same - $$$A_u \gt A_v$$$ - $$$A_u \lt A_v$$$ This maximum node can be found by binary lifting technique.

Time complexity — $$$O(N log^2N)$$$ and works fine within $$$3$$$ seconds.

My code

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

What will be the expected rating of the 2nd question?

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

Nice editorial , hints are available for every problem.

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

Can someone explain C? Why suffix though?

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

I am not getting Problem C solution can someone explain it.

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

Satyam_343 is legend!

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

for C, a little optimization: say that current suffix has length l. then in the summation we will be summing 2^(k-1) from k=1 to l, but this is just 2^(l)-1. thus we only need to sum (2^length)-1 over all consecutive strings of 1s and all consecutive strings of 0s. example: 101101111 1 — length 1; 0 — length 1; 11 — length 2; 0 — length 1; 1111 — length 4; summing 2^(length)-1 gives 1+1+3+1+15=21, as desired.

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

GOOOOD round!

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

cool

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

someone please explain to me problem C , i got humbled

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

    So let's see what makes an extension good, shall we? s = 01101000 t(extension) = 0_1_1_0_1_0_0_0

    2 — So for [1, 3] to be good, we need to place 1 in the second slot 4 — So for [1, 5] to be good, we can place 0 or 1 actually, and this is kinda the main idea, let's see why. So let's check the number of ones and zeroes from 1 to 3(inclusive). One 0, and two ones, correct? So when we jump from [1, 3] to [1, 5], we automatically increase the number of ones by one because t[5] contains 1. And since 1 was median beforehand, when we increase it by 1 we can also increase the number of zeroes by 1. Next, we have 0, and if we increase the number of zeroes by one, that would make the number of ones and zeroes equal, so we have to add another 0. From this, we can see that if the median for [1, i — 2] is x and t[i] is x, then t[i — 1] can be anything, since when we do that either number of 'x' increases by 2, which makes it median(obviously) or x AND the other one by 1 which keeps it at median.