By awoo, history, 4 years ago, translation, In English

Hello Codeforces!

On Jan/14/2021 17:35 (Moscow time) Educational Codeforces Round 102 (Rated for Div. 2) will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.

You will be given 6 or 7 problems and 2 hours to solve them.

The problems were invented and prepared by Roman Roms Glazov, Adilbek adedalic Dalabaev, Vladimir vovuh Petrov, Ivan BledDest Androsov, Maksim Neon Mescheryakov and me. Also huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.

Good luck to all the participants!

Our friends at Harbour.Space also have a message for you:

Hey Codeforces and Happy New Year!

To kick off 2021, we want to introduce you to new opportunities!

Undoubtedly, Harbour.Space is always happy to see Codeforces participants among our students! Young talents who are eager to learn, challenge themselves, seek continuous development are our top priority.

That’s why we want to announce our amazing apprenticeship program.

Our mission is to spark positive impact cycles between promising young talent, the tech industry, and innovative educators. We continuously work on finding the perfect match between talent and companies.

Check out a success story from one of our first apprenticeship program students.

David is a UX/UI specialist from Georgia who received a full scholarship from venture capital fund, OneRagtime.

But there are plenty more apprenticeship opportunities coming in the fields of technology, entrepreneurship, and design. Interested? Keep in touch and follow us on LinkedIn for more fantastic opportunities.

Good luck on your round, and see you next time!

Harbour.Space University

Congratulations to the winners:

Rank Competitor Problems Solved Penalty
1 jiangly 7 201
2 hank55663 7 210
3 BigBag 7 282
4 Lawali 7 283
5 FluffyT 7 306

Congratulations to the best hackers:

Rank Competitor Hack Count
1 ariloc 35:-1
2 smax 34:-9
3 mrkarlo 27:-5
4 VTifand 19
5 BlueGagosipda 21:-22
242 successful hacks and 872 unsuccessful hacks were made in total!

And finally people who were the first to solve each problem:

Problem Competitor Penalty
A Geothermal 0:01
B Geothermal 0:02
C SSRS_ 0:09
D Alfalfa_w 0:09
E _FlyingColor_ 0:16
F Apsara 0:40
G tfg 0:48

UPD: Editorial is out

  • Vote: I like it
  • +292
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it -73 Vote: I do not like it

Hope this time it will be real educational and not just "educational". Anyway good luck to everyone!

»
4 years ago, # |
  Vote: I like it -80 Vote: I do not like it

Don't forget to notice the usual start time!

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -31 Vote: I do not like it

    RIP SupaHotFire meme skils

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +13 Vote: I do not like it

      it's ok that happens sometimes I'll try to make a better one soon

»
4 years ago, # |
  Vote: I like it +65 Vote: I do not like it

Congratulations to David! It is cool to see internship and job opportunities on CodeForces, even though they are not directly related to competitive programming. Many people start CP to improve programming skills in general, and Educational Contests work well to tie these fields together.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +45 Vote: I do not like it

    Congrats dude you managed to survive the downvote apocalypse going on in here :P

»
4 years ago, # |
  Vote: I like it -20 Vote: I do not like it

My first contest in CF ;)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    good luck, bro! This is my first experience too :)

»
4 years ago, # |
  Vote: I like it +24 Vote: I do not like it

pikmike -> awoo

»
4 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Hoping for a round which is educational

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    Educational rounds have never failed to be educational bro, you don't need to worry about that :)

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

If we hack any solution, will we get any points in this contest?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    No,you will not get any points but the hacked solution will count as wrong solution.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      ohh, okay..

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it +1 Vote: I do not like it

      but there is an advantage, if u hacked some1 above u and if he is hacked he will be down u, u can go 1 step up and that's good

»
4 years ago, # |
  Vote: I like it +14 Vote: I do not like it

When people find out this guy IS pikmike, they are like: awoo

»
4 years ago, # |
  Vote: I like it +41 Vote: I do not like it

My first contest drunk ! Less gooo !!!

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

nice C. Also i have no idea why my B, D got AC. Someone please hack them.

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

IITKWPCJ — Harder version of B by PraveenDhinwa

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

D is segment tree isn't it?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Yes just keep track of the minimum and maximum prefix sum

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    I solved it using prefix and suffix arrays.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    might be, but will be an overkill.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yes but my code is very large and weird. Waiting for another solution (if there exist one)

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    No segment tree, required, for both prefix and suffix store the maximum and minimum sums.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    I didnt manage to finsih the code but it is :

    Something along these lines
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I used a sparse table, though it could have been done by maintaining a minimum of prefix/suffix and a maximum of those two.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    The trick is to avoid all possible off-by-one errors. I did by try'n'error for about an hour.

»
4 years ago, # |
  Vote: I like it +19 Vote: I do not like it

How to solve E? I tried using Dijkstra but it didn't pass

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it
    Spoiler
    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I did something similar here But I kept getting WA on test 5 and now I check there's only 1 number that differs I don't know why

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        it's just showing that 1 number differs but actually there are more if you look carefully

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +86 Vote: I do not like it
    Problem E solution
    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Why you can choose an arbitrary edge to add or subtract? Did I misunderstand the problem?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +21 Vote: I do not like it

        Its kind of greedy. Notice that you are looking for the shortest path between node 1 and all others. If you must take the cost of some edge twice, It is always best to take the smallest edge weight on the path. Similarly, If you are allowed to remove the cost of one edge on the path, it is always best to use the largest edge weight on the path. Dijkstra naturally takes this into account.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    We can convert edge {u, v, w} to three edges {u, v, w, 0}, {u, v, 0, 1}, {u, v, 2 * w, 1}. The fourth element in the edge is use as minimal or as maximal edge. Introduce Dynamic Programming d[v][flag1][flag2] — minimal answer in vertex v, where flag1 = 1, when we used maximal edge, and where flag2 = 1, when we used minimal edge. Calcing the Dijkstra. Answer for vertex v is d[v][1][1]

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

How to solve C ??

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it +6 Vote: I do not like it

    It was too complicated for me to find and proof the solution and thus i brute forced and observed the pattern .

    from i=1 to 2*k-n-1 you need to print i itself . After that you need to start from k . For example for n=5,k=5 : 1 2 3 4 5. for n=6 , k=5 : 1 2 3 5 4 . n=7,k=5 : 1 2 5 4 3 . n=8,k=5 : 1 5 4 3 2 . n=9,k=5 : 5 4 3 2 1.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    It can be proved that the number of inverse of array B must be more than or equal to A regardless of any permutation. I separated array into two parts p[1],p[2],...p[k-(n-k)-1] and p[k-(n-k)],p[k-(n-k)+1],...,p[k],p[k-1],p[k-2],...,p[k-(n-k)]. If you take a look at the latter part, you can see that, for any pairs of i<j between k-(n-k) and k, there is always one p[i] appeared before p[j] and another p[i] appeared after p[j]. So the number of inverse in the latter part is always constant because any pairs of i and j have exactly 1 inverse. In the first part, the number of inverse in array A is 0 because it is arranged in ascending order and every elements of first part in array A in less than second part. So basically, we have to create any array that the first part is the same as A(or else inverse will be more than A) which is 1,2,3,...,k-(n-k)-1 and second part can be any permutation of k-(n-k),k-(n-k)+1,...,k. and lexicographically largest permutation is k,k-1,k-2,...,k-(n-k).

  • »
    »
    4 years ago, # ^ |
    Rev. 9   Vote: I like it +6 Vote: I do not like it

    I'll try to explain with examples

    Let's use $$$k = 5, n = 9$$$
    Initially
    $$$P$$$ = $$$1, 2, 3, 4, 5$$$
    And $$$B$$$ = $$$1, 2, 3, 4, 5, 4, 3, 2, 1$$$
    Notice when you swap $$$5$$$ with $$$4$$$ in $$$P$$$ It doesn't change the number of inversions (because of the mapping b[i] = p[a[i]])
    $$$P$$$ becomes $$$1, 2, 3, 5, 4$$$
    And $$$B$$$ becomes $$$1, 2, 3, 5, 4, 5, 3, 2, 1$$$
    So you can continue swapping the largest number to the left as far as the number you want to swap with has a duplicate value on the right-hand side of $$$B$$$

    Let me use a smaller example
    You have $$$k = 3, n = 4$$$
    $$$P$$$ = $$$1, 2, 3$$$
    $$$B$$$ = $$$1, 2, 3, 2$$$
    You can swap $$$3$$$ to the left once in $$$P$$$
    $$$P$$$ becomes $$$1, 3, 2$$$
    $$$B$$$ becomes $$$1, 3, 2, 3$$$
    And you can't swap $$$3$$$ again
    Because if you swap it left you will increase the number of inversions

    In general
    If you have a sequence $$$P$$$ = $$$1, 2, 3, 4, 6 ... k$$$ and $$$n$$$
    Reversing the last $$$n - k + 1$$$ in values in $$$P$$$ is your solution and the number of inversions remains the same.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      why don't we just stop after swapping the last two elements? Can you please explain that because I can't find a test case where just doing that will fail.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        ya exactly. i did this as well. a: 1,2,3,4,5,...k-1,k,k-1,k-2,k-3..k-(n-k) b: 1,2,3,4,5,...k,k-1,k,k-2,k-3,...k-(n-k) the only difference is the 3 numbers in middle. in A they gave 1 inversion. in B also they are giving 1 inversion. and for the rest of k-3,k-4,k-5....2k-n,the number of digits greater before them remain same. so in all cases inversions remain same and b is lexicographically greater. and when n==k just print 1,2,3,....k-1,k. pls explain if anyone sees a fault in this

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          maybe the question wants us to create the greatest possible lexigraphic configuration and not just greater. haha! we were so close to the solution dude.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            oh hmmmm. b is lexicographically maximum. i thought amongst a and b, b must be greater. cool my fault then. thanks mate

      • »
        »
        »
        »
        4 years ago, # ^ |
        Rev. 4   Vote: I like it +3 Vote: I do not like it

        Maybe this will help
        Full visualization for $$$n = 7$$$, $$$k = 4$$$
        $$$P$$$ = $$$1, 2, 3, 4$$$
        $$$B$$$ = $$$1, 2, 3, 4, 3, 2, 1$$$
        Swap $$$4$$$ and $$$3$$$ in $$$P$$$
        $$$P$$$ = $$$1, 2, 4, 3$$$
        $$$B$$$ = $$$1, 2, 4, 3, 4, 2, 1$$$
        Swap $$$4$$$ and $$$2$$$ in $$$P$$$
        $$$P$$$ = $$$1, 4, 2, 3$$$
        $$$B$$$ = $$$1, 4, 2, 3, 2, 4, 1$$$
        Swap $$$4$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 1, 2, 3$$$
        $$$B$$$ = $$$4, 1, 2, 3, 2, 1, 4$$$
        Swap $$$3$$$ and $$$2$$$ in $$$P$$$
        $$$P$$$ = $$$4, 1, 3, 2$$$
        $$$B$$$ = $$$4, 1, 3, 2, 3, 1, 4$$$
        Swap $$$3$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 3, 1, 2$$$
        $$$B$$$ = $$$4, 3, 1, 2, 1, 3, 4$$$
        Swap $$$2$$$ and $$$1$$$ in $$$P$$$
        $$$P$$$ = $$$4, 3, 2, 1$$$
        $$$B$$$ = $$$4, 3, 2, 1, 2, 3, 4$$$
        So the final value for $$$P$$$ is $$$4, 3, 2, 1$$$
        Notice the inversion never increases or decreases

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      I wish I could upvote you twice. No youtube videos really helped but your comment did. Thanks Sir. Now I can sleep well ;-)

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Is it possible to solve D in linear time? Only issue I had was how to find minimum and maximum for suffix. For prefix it's easy.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Lol! reverse the original array.

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    if you found the solution for prefix ,why you didnt reverse the array and did the same thing?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    You don't need to find maximum/minimum prefix of suffix. Instead, you can calculate sum in two segments and substract minimum/maximum suffix, which can be calculated similar to minimum/maximum prefix.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    first traverse from front then from back, keeping track of current position and max. and min. it has reached.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Could someone please explain why the answer for vertex 7 in test case 3, problem E is 3?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +14 Vote: I do not like it

    You can use an edge more than once

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      Thanks man, i wasn't able to figure it out

      For those who still have this confusion, the optimal path for 7 is-

      1->7->4->7

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve D, anyone can explain?, i got run time exceed

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried square root decomposition and was expecting it to work But got TLE because I use Python RIP. Maybe it should work in CPP O(M root(N))

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

This contest made me realize that I should maintain a segment tree library.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

how to solve D and F ? Anyone explain.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    D can be solved by range minimum & maximum queries in Segment tree.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +35 Vote: I do not like it

      Or just by calculating prefix/suffix maximums/minimums, no need for segtree.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      InANutshell What are u trying to store there in seg tree?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I did storing the a pair of values, which is minimum and maximum of the prefix sums of all operations of that segment.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    I did D by maintaining prefix and suffix minimums/maximums without segment trees. Just eliminate the effect of l to r by adding the cumulative sum to the min and max of the remaining suffix array. The answer is total_max — total_min + 1 Total_min and total_max are overall min and max(from prefix array and suffix array before l and after r respectively) after eliminating the effect of the segment l to r

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks, I understood it now.

      I was thinking of Adding the cumulative sum to all elements in suffix array and then to eliminate duplicate elements (which was not even needed...)

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Can you explain the logic behind adding the cumulative sum to the min and max of suffix array ? I cant understand it very well.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +2 Vote: I do not like it

        Hey, so you would add the cumulative sum to nullify the effect of the segment (l to r), instead if adding it to the whole suffix array, you can only add it to min and max because the change is uniform. You only need min and max from the prefix and suffix because all the points between them will be travelled automatically (because the step size is only 1)

        PS — you can imagine it like a continuous graph, in which you remove a segment in between and join the ends if the other 2 segments, you have to bring the right end up or down to meet the left end ( so you add the cumulative sum * -1 which can be positive or negative to negate the effect)

        Idk if this is helpful, not so good at explaining stuff

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        We need to observe one thing that if we want to know the distinct numbers possible in some ++--+-+++... string then the no of distinct possibilities are mx — mn + 1. (mx is max no possible and mn is min no possible).

        consider 4 vectors pre_ma, pre_mi, suff_ma, suff_mi

        while calculating these vectors we consider that value of x starts from 0

        pre_mi[i] — what is the min value that we came across until index i if we started from index 1.

        pre_ma[i] — what is the max value that we came across until index i if we started from index 1.

        suff_mi[i] — what is the min value that we came across until index N if we started from index i

        suff_ma[i] — what is the max value that we came across until index N if we started from index i.

        Now for each query, we have to consider 1 to l-1 and r+1 to N as combined string and do these operations. Instead we find the max and min possible values differently for both of these prefix and suffix strings.

        So, for prefix string since the value of x starts from 0 we can directly consider pre_mi[l-1] and pre_ma[l-1], but for this suffix string the value of x doesn't start from 0, (But we have stored the vectors if the value of x starts from 0), but this suffix string starts at some value X (Here X denotes the sum of prefix string). so we have to consider (X + suff_mi[r+1] as the min value occured in this suffix string) , same goes for maximum in suffix string.

        Final answer would be max(suffix max val , prefix max val) — min(prefix min val, suffix min val) + 1.

        Link to my code

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          thanks learned a new way to calculate suffix maximum...) it was helpful

»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Hi, I encountered some strange errors while submitting a solution in Java for Problem D in the Codeforces Educational Round 102,

The code works perfectly in my local system, it even works correctly in an online Java Compiler(OnlineGDB). However, it was unable to read strings correctly in the Problem D.

My Submission: 104337369

Could someone please guide why this is happening..

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can i know the aproach for problem div2A

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    traverse the input array, if there is no number greater than d, print yes. Now sort the array. If the sum of first two numbers is less than or equal to d, then it means that any number which is bigger than d can be replaced by the sum of these two numbers. But if their sum is not less than or equal to d, then we can be sure that no other sum in this array will be smaller than this. therefore, after sorting

    if(a[0]+a[1]<=d) print yes else print no

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Thank you. I could only solve first case.never thought of sorting the input array.

»
4 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Editorial, please

»
4 years ago, # |
  Vote: I like it +14 Vote: I do not like it

$$$D$$$ was easier than $$$C$$$ at least to me.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    Same for me, I find it hard to beleave that so much people solved C. It looks kind of unsolvable to me, I still did not read any near-to-understandable explanation.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +15 Vote: I do not like it

      The only thing you need to notice is that in the segment $$$[k - (n - k), ..., k, ..., k - (n - k)]$$$ no matter what permutation you choose the number of inversions in this segment will not change (and will equal $$$(n - k)^2$$$ but that's extra info irrelevant here).

      So you can't afford any other inversion hence the head of your list must be $$$[1, 2, 3, ..., k - (n - k) - 1]$$$. Now to get the maximum lexicographical sequence you should transform $$$[k - (n - k), ..., k, ..., k - (n - k)]$$$ to $$$[k, k - 1 ..., k - (n - k), ..., k - 1, k]$$$ and to do so we use the permutation $$$[1, 2, 3, ... k - (n - k ) - 1, k, k - 1, k - 2, ..., k - (n - k)]$$$

      • »
        »
        »
        »
        4 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        How do you prove that no matter what permutation you choose the number of inversions in this segment will not change and will equal $$$(n−k)^2$$$ ?

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Thats the part I did understand. This is, because if you change two (or more) numbers to each other, you allways change two of such pairs.

          As an example, that part of the list looks like:

          3 4 5 4 3 So, no matter which digits are exchanged to each other, it allways happend twice in respect to the positions, and hence number of inversions.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        So if $$$b = [k - (n - k), ..., k, ..., k - (n - k)]$$$ and $$$p = n - k$$$, $$$size(b) = 2p+1$$$.
        By symmetry,

        $$$inv(b) = \# \left\{ i<j | b_i>b_j \right\} = \# \left\{ i<j | b_i<b_j \right\}$$$

        Then,

        $$$ 2 inv(b) = \# \left\{ i<j \right\} - \# \left\{ i<j | b_i=b_j \right\} = (size(b)-1)size(b)/2 - p = 2p^2 $$$

        Finally,

        $$$inv(b) = p^2 = (n-k)^2$$$
    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      might be because of massive cheating again . From coding perspective it was only 2-3 line solution and thus it was easy to spread and fool the moss .

      To be honest it was way difficult than D and very incomprehensible.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Well, now, like 12 hours later, I think I understood the problem. Maybe I just needed a bit longer than other people.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          seeing your current and maximum rating it's hard to digest you couldn't solve it and lot of people did . Something fishy going on these days.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +1 Vote: I do not like it

            Not so sure, it's easy to guess the solution to the problem. In contest, you don't have to understand why it works.

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it 0 Vote: I do not like it

              In contest, you don't have to understand why it work

              Then i would get WA on pretest 2

              • »
                »
                »
                »
                »
                »
                »
                »
                4 years ago, # ^ |
                Rev. 2   Vote: I like it +4 Vote: I do not like it

                I guessed the solution at the beginning, tested on some small test cases, gained some intuition to why it works, and YOLOed. In contest, many people don't do the second part, much less the third. When you have no other ideas, sometimes its fine.

                I'm not saying there was no cheating or anything, just saying that I don't think the solve count is too suspicious — you kinda see the pattern when you look at enough test cases.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It was quite easy to analyze some cases with backtracking and then observe the pattern. Maybe this was the reason of so many AC's.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you explain how did you do D?

»
4 years ago, # |
  Vote: I like it +15 Vote: I do not like it

How to solve problem F ?

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +87 Vote: I do not like it

    Build a flow network as follows: let's create a source $$$s$$$, a sink $$$t$$$, and a vertex for each element. We will try to model the problem as the minimum cut in this network.

    For every element $$$i$$$, there are several elements $$$j$$$ to the left of it that should be taken if we take it. Let's add a directed edge with infinite capacity from $$$i$$$ to all such elements. For elements will positive $$$b_i$$$, add a directed edge from $$$s$$$ to them with capacity equal to $$$b_i$$$. For elements will negative $$$b_i$$$, add a directed edge from $$$i$$$ to $$$t$$$ with capacity $$$|b_i|$$$.

    What does an $$$s$$$-$$$t$$$ cut in this network represent? Let's say that all elements in the same part with $$$s$$$ are taken into the answer, and all other elements are ignored. Let's say that we have some $$$i$$$ that is taken into answer and depends on some element $$$j$$$ that is not taken. Then there is an infinite-capacity edge from $$$j$$$ to $$$i$$$, and it goes through the cut, so the value of the cut is infinite (and we are searching for a minimum cut, so this cannot happen). For each positive $$$b_i$$$, if $$$i$$$ is not taken, the value of the cut increases by $$$b_i$$$ (since the edge from $$$s$$$ belongs to the cut), and for each negative $$$b_i$$$, if $$$i$$$ is taken, the edge from $$$i$$$ to $$$t$$$ belongs to the cut, so $$$|b_i|$$$ is added to the value of the cut. So, the minimum cut actually minimizes the sum of positive $$$b_i$$$ that are not taken, minus the sum of negative $$$b_i$$$ that are taken, so it gives us the optimal answer.

    There's one issue though. This network can easily reach $$$O(n^2)$$$ edges, and that's too much. To reduce the number of edges to something like $$$9n$$$, for each $$$i$$$, consider all divisors of $$$a_i$$$ (including $$$a_i$$$ itself) to the left of it. If there are several equal divisors, then taking the closest of them ensures that we take all other divisors into the answer, so actually, for each divisor of $$$a_i$$$, we need to consider only the closest occurrence of this divisor to the left of $$$i$$$, and add an infinite edge from it to $$$i$$$.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      This might be a dumb question (I'm pretty new to flows), but what would be the complexity of this algorithm? Using Dinic's, wouldn't this be $$$\mathcal O(V^2E)$$$, and with $$$V = 3000$$$ and $$$E \approx 9 \cdot 3000$$$, shouldn't this TLE? Or there also just might be some property about this flow graph that makes Dinic faster that I'm not aware of.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +25 Vote: I do not like it

        The distinctive feature of many flow problems is that it is either very hard or even impossible to construct a testcase on which an algorithm performs anywhere near its worst-case complexity.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Ah, that makes sense. I guess if a flow solution exists, it's always worth to try it and see if it passes. Thanks for the reply!

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +28 Vote: I do not like it

        Yes, I've also considered this problem. In fact, the model solution is written with the implementation of maxflow in $$$O(VE \log F)$$$ (Dinic with scaling), so asymptotically it should be fine. But my implementation of regular Dinic also passes all of my test cases, I haven't found a test case which it gets TL on.

        So, actually, we have a 100% working solution, but we guess that some asymptotically bad solutions might pass.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +32 Vote: I do not like it

        In this problem a path saturates a source edge or a sink edge always because the other edges have infinite capacity so the actual complexity is O(V paths) * O(E for finding a path) for any max flow algorithm.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Suspicious submission for hacks I think the hacker made an alternate account for hacking this.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why would anyone do this? Afaik you get nothing for hacking in this contest.

»
4 years ago, # |
  Vote: I like it +36 Vote: I do not like it

Whoever concocted this is genius. They've practically lined themselves up to be caught.

https://codeforces.net/contest/1473/status/A?order=BY_CONSUMED_TIME_DESC

»
4 years ago, # |
  Vote: I like it -41 Vote: I do not like it

VIDEOTUTORIAL FOR PROBLEM A AND B WITH DETAILED EXPLANATION . I ALSO TRIED TO EXPLAIN LINE BY LINE CODE . I HOPE YOU GUYS WILL ENJOY THE VIDEO LINK PROBLEM B :https://www.youtube.com/watch?v=H3qBEDYwwX4 LINK PROBLEM A :https://www.youtube.com/watch?v=YjC6CcxYxo8

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In problem $$$C$$$, It's never said that $$$b$$$ has to be the sequence with the least number of inversions. It can be found that number of inversions of $$$a$$$ is $$$(n - k)^2$$$ and the sequence $$$b$$$ builds off the permutation $$$1,2,..,k,k-1$$$ also has the equal number of inversions as $$$a$$$ and it should suffice to be the solution when $$$n > k$$$.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's never said that $$$b$$$ has to be the sequence with the least number of inversions

    True, but it is said that

    [...] and $$$b$$$ is lexicographically maximum.

    Also note that

    It can be proven that $$$p$$$ exists and is unique.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think you missed the requirement where B must be lexicographically maximum.

»
4 years ago, # |
  Vote: I like it +47 Vote: I do not like it

Screenshot-320

It hurts!

  • »
    »
    4 years ago, # ^ |
      Vote: I like it -35 Vote: I do not like it

    roz adhoc problems karke man nahi bharta kya patang udao gilli danda khelo! come out of this artificial life.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem C and D video solutions — solution

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Unable to understand C even after looking the to the test cases that didn't passed. Anyone here could you please help me with proper understanding of C.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I did same mistake with you during contest.

    Try to solve this testcase by your hand

    1 7 4

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Go to secondthrad's youtube channel , he has explained that problem quiet nicely.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey, I have a doubt regarding problem C.Is the number of inversions in 1 2 3 2 1 is same as that in 3 2 1 2 3?

»
4 years ago, # |
  Vote: I like it -8 Vote: I do not like it

hey someone please help me to debugging my code i got WA in test case 8 of problem E;

Spoiler
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Your bfs solution is incorrect because edges in this task are weighted and that's why bfs won't work in this case. Try to use Dijkstra algorithm.

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

https://codeforces.net/contest/1473/submission/104345925 can someone explain what's happening here?

while time.time() &mdash; cur < 1.7:
    pass
  • »
    »
    4 years ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    I think this violates Rule #6 by destabilizing the checking system (trying to increase the queue size by increasing the running time)

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I have a big question could anyone tell me in Problem E how in the third sample the minimum weight to vertex 5 is 7? I can't find a path with lower than 8

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

Hey all, if you missed the post-contest stream that I did on https://www.twitch.tv/stevenkplus, here is the youtube recording: https://youtu.be/3o1Na9Qnaio.

Will edit this comment with links to my submissions (containing solution notes) once I perform the submission process :)

»
4 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Problem E is really cool! I don't know why I didn't consider traversing an edge twice.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

For anyone stuck in D, https://youtu.be/mMFkvyeRFQY

»
4 years ago, # |
Rev. 2   Vote: I like it +95 Vote: I do not like it

People using Segment tree and MO's algo in problem D

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Nah, seg tree is really close to the linear solution anyway.

»
4 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Does anyone have any idea what's the mistake in all the solns of E that were hacked?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    if(no.a>dist[no.b.a][no.b.b])continue;

    it the pair in the priority_queue has more distance than the shortest
    path found till now then don't iterate further.Codes which didn't
    add this condition got hacked(TLE).weak pretests

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

I got lucky for problem C. I somehow looked at the testcases and figured out what to do. This has happened to me in previous contest too . xd

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone instead of flexing that it can be solved by prefix/suffix sum explain how to solve D . I know prefix,suffix but i don't know how to use that in this problem.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    create the following arrays :

    MaxTillHere[] -> stores the max value upto a particular index MinTillHere[] -> stores the min value upto a particular index

    then, using backward traversal create the following array :

    MaxFromHere[] -> stores the max increase we'll get after a particular index MinFromHere[] -> stores the max decrease we'll get after a particular index

    now the answer is simple, for each query (l, r) : int max = MaxTillHere[l — 1] + val[i] + MaxFromHere[r] int min = MinTillHere[l — 1] + val[i] + MinFromHere[r]

    ans = max — min + 1

    I hope my answer was clear. Some index value might be wrong here, but i hope you've got the gyst of the solution!

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      you haven't solved this problem and telling wrong/incomplete solution .From next time solve it first. It's sad i can't take my upvote back.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +5 Vote: I do not like it

        Here. I solved it just for you. Problem D solution

        Well you can downvote this one, if it makes you feel any better. Next time, either solve it yourself or don't bitch about people who try to help you.

»
4 years ago, # |
  Vote: I like it +17 Vote: I do not like it

When will the rating be updated for this round.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Educational contest take too much time for ratings updation and editorial normally

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Video Tutorial for problem A,B and D link of problem D : https://www.youtube.com/watch?v=botAQ-AZNOQ

link of problem B : https://www.youtube.com/watch?v=H3qBEDYwwX4

link of problem A : https://www.youtube.com/watch?v=YjC6CcxYxo8&t=263s

Hope you guys will enjoy and understand the intution behind the solutions !!!

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

why did they temporarily roll the rating changes back ??

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

why i am getting negative points? i thought in 10 min solved no penalty

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Points are counted depending on other participants, most likely someone solved more or as many problems as you, but at the same time was the lowest rating

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      what if i register and 0 submission solved 0 problem i am get negative point?

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        if you are registered, but you have not sent anything for the entire competition, you will not receive or lose anything

»
4 years ago, # |
  Vote: I like it +26 Vote: I do not like it

is it rated for the participants with rating greater or equal to 2100? i fount some people who geater than 2100 is rated

»
4 years ago, # |
  Vote: I like it +23 Vote: I do not like it

My rating was above 2100 before taking this contest, but it was changed because of it. Could anyone tell me why?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +21 Vote: I do not like it

    I think it was applied as a rating when "Codeforces Round #695 (Div. 2)" is temporarily rolled back. At that time, our rating was lower than 2100.

»
4 years ago, # |
  Vote: I like it +9 Vote: I do not like it

Hello Codeforces!

I basically got a message that I cheated in this round, and that my rating won't change.

The message I got

I am writing this comment to inform to the codeforces headquaters that the plagarism check system has made a misjudgement.

I was pretty shocked to see this message and other people's codes.

They were similar, and some were even the exact same.

I found no code that was exactly the same to my code, but some were astonishingly similar.

Problem A in this contest was a very simple problem, that had a very simple solution, so there could be some coincidences in people's code.

Also, I confirm that I don't even have a telegram account and have never used Ideone or other online judjes in this contest.

I understand codeforces' work to catch cheaters to make codeforces a better community.

However, for the reasons I stated above, I want to get my rating back.

Thank you! :)

+) I am curious about when, and how I will get my rating back. Will the headquaters contact me via email or codeforces talk?

»
4 years ago, # |
  Vote: I like it +20 Vote: I do not like it

I took part in this unrated contest (for Div. 1) and found my rating changed afterwards. Why? Mistake?

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Where is Editorial? Also Can you make problem statement clear? Problem C was so much confusing. I understood it only after reading examples.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

I dont usually comment because of my low rating which gathers me downvotes...but the broad range of topics tested in this round, be it the use of data structures or algorithms in this round is appreciated. It didn't seem too adhoc like other rounds involved some known concepts to a perfect extent and again the breadth of topics of the questions- just amazing! Kudos to the authors of the contest. Well done! Editorial was fast, question statement lengths and test strengths were optimal. In short, one of the best contests I have ever participated on Codeforces.