ItsNotMeItsYou's blog

By ItsNotMeItsYou, 9 days ago, In English

Merhaba Codeforces!

We are proud to invite you to Codeforces Round 1118 (Div. 2), which will be held on Aug/29/2026 17:35 (Moscow time).

The round will be rated for participants whose rating is below 2100, but higher rated users are also welcome to participate out of competition. You will be given 6 problems, one of which will be divided into a subtask, and 2 hours to solve them. Also, there is at least one interactive problem, so you are recommended to read the guide to interactive problems if you have not encountered them before.

The problems were authored by me (ItsNotMeItsYou), carcinisation, mychecksdead and Seferoglu.

This round was prepared by some members of the 2025 and 2026 IOI team of Türkiye, and we hope you enjoy all our problems.

We would like to thank:

Score distribution: $$$500-(750+1000)-1250-2000-2250-3000$$$

Good luck & have fun!

UPD: The editorial is out! Sorry for underestimating the difficulties of the problems, especially B2 and D. We tried to serve as many cool problems as we could. And apparently, this led to some difficult ones.

Congratulations to the winners:

Official participants (subjects to change):

Unofficial participants (subjects to change):

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

»
8 days ago, hide # |
Rev. 4  
Vote: I like it +16 Vote: I do not like it

ItsNotMeltsYou Codeforces!

  • »
    »
    8 days ago, hide # ^ |
     
    Vote: I like it +29 Vote: I do not like it

    As a tester, I can confrim that this is a funny joke and I laughed.

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

      Were you said that you are testing Div 1 + 2 ? Bro WTFF THIS ROUND WAS LIKE SO LESS POINTS LIKE WHO MAKE B2 THAT MUCH HARD with 750 points GUYS IT'S DIV 2 NOT 1 SHOW MERCY MAN like wtf

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

        Yeah I knew it was div2 idk how much they changed since the version I tested tho. Im sorry to hear this I know how frustrating it can be when a contest is hard.

»
8 days ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

as a tester, i can write comments

»
8 days ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

As a not tester, finally Merhaba Codeforces!

»
8 days ago, hide # |
 
Vote: I like it +16 Vote: I do not like it
»
8 days ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Real

»
8 days ago, hide # |
 
Vote: I like it +43 Vote: I do not like it

As a tester, I didn’t generate tests for any problem

»
8 days ago, hide # |
 
Vote: I like it +28 Vote: I do not like it

As a not tester, I can confirm the problems will test me.

»
8 days ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

I love how ItsNotMeltsYou is a GM in the announcement... I guess he/she agrees with Errichto's idea...

»
8 days ago, hide # |
 
Vote: I like it +29 Vote: I do not like it

As a problem, hope the participants are fun

Also crazy B distribution

»
8 days ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

It's crazy that I haven't seen subtasks in Div.2 B since I came to Codeforces:)

»
8 days ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

Sonunda, we have a Turkish round

»
8 days ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

Planning to give this round while eating Turkish Baklawa :yum (Apologies for wrong spelling in advance).

»
8 days ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

wtf strong

»
8 days ago, hide # |
 
Vote: I like it +19 Vote: I do not like it

As a tester I can say that I tested the round.

I also can say that if you are reading this you are obligated to participate.

»
8 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

as a person i cannot confirm that the problems exist

»
8 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

A Turk Round

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Finally, a contest with an interactive problem

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

"new mask same task"(by iron man)

»
7 days ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

As a not tester this will be the best contest ever on CF

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

B1 B2 are crazy

»
7 days ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Great contest, Hope you guys have fun!

»
7 days ago, hide # |
 
Vote: I like it +25 Vote: I do not like it

As a tester, my favorite moment was when carcinisation said it's testing time and tested all over the place!

»
7 days ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

OHAA TR ROUND LESGOO

»
7 days ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

going to be my first contest here.. :)

  • »
    »
    7 days ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    first contest and directly Div 2 ??

    • »
      »
      »
      7 days ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Don't know how this system works, just registered for it..

      • »
        »
        »
        »
        7 days ago, hide # ^ |
         
        Vote: I like it +3 Vote: I do not like it

        im a newbie too but i only solve Div 4 past contest ques... should i register for it too???

        • »
          »
          »
          »
          »
          7 days ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Great to know that I'm not the alone newbie here :) I think you should give this contest a try..

          • »
            »
            »
            »
            »
            »
            7 days ago, hide # ^ |
             
            Vote: I like it +3 Vote: I do not like it

            yeahhhh but havent tried any Div 2 problem... i think i should give it a try

            basically problems are categorized here... Div 4 for beginners Div 3 for intermediate type and so on.., higher you go problems become difficult

            • »
              »
              »
              »
              »
              »
              »
              7 days ago, hide # ^ |
               
              Vote: I like it +3 Vote: I do not like it

              I'm a final year engineering student and still don't have any good amount of knowledge about these platforms.. So just a newbie here trying to figure out things on my own.. Can you help me understand these concepts? I mean we can connect.. I have tried reading documentations but they are just too long to finish in hr :(

            • »
              »
              »
              »
              »
              »
              »
              7 days ago, hide # ^ |
               
              Vote: I like it 0 Vote: I do not like it

              Tip: You should solve all divisions, or at least try div 3. Div 4 problems are mostly really easy even for newbie level and won't get you very far

              • »
                »
                »
                »
                »
                »
                »
                »
                7 days ago, hide # ^ |
                 
                Vote: I like it 0 Vote: I do not like it

                yeahhh... but even in Div 4 last ques like F or G are good though. Well I solve Div 3 and 4 both. Haven't touched Div 2 or 1.

        • »
          »
          »
          »
          »
          7 days ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          You should try doing div2s because there are only 4 div4s last year. We might get GTA VI before a div4...

          • »
            »
            »
            »
            »
            »
            7 days ago, hide # ^ |
             
            Vote: I like it 0 Vote: I do not like it

            lolll... that's hilarious... alright i will register for this... (⁠ ⁠╹⁠▽⁠╹⁠ ⁠)

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The "You" is reverse-nutella T_T

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope get rating up XD

»
7 days ago, hide # |
Rev. 3  
Vote: I like it -10 Vote: I do not like it

ItsNotMeItsYou I know you're from Turkey, and I'm from Azerbaijan. :)

»
7 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

before seeing author's profile i didn't know that rating may be negative

»
7 days ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

*realizing that all of the authors agree to Errichto's opinion*

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

6 7

»
7 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

mecukuryurt we need to lock in dude

»
7 days ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

I am really interesting for the contest [contest:Codeforces Round 1118 (Div 2)] .. Thanks to [user:ItsNotMeltsYou] and Me som__ is preparing for this.. All the best to all.. Good buy .. Sayonara...

»
6 days ago, hide # |
 
Vote: I like it +3 Vote: I do not like it
»
6 days ago, hide # |
 
Vote: I like it -30 Vote: I do not like it

as a not tester give me contri

»
6 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good luck to all participants!

»
6 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

waiting for contest

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

First time seeing 2B's in a div 2 since I started. Context: I have started very recently :)

»
5 days ago, hide # |
Rev. 2  
Vote: I like it +16 Vote: I do not like it

Finally Turkish contest. This contest will be different in good way. Good luck for everyone!

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I just want to add 50 rating,and up to pupil..... if my dream comes true,it will be a fantastic gift in the end of summer holiday! (I'm a chinese student,and must go to school in 0901,the contest is the last one in summer holiday TAT)

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Looking forward for this contest for having at least one interactive problem

»
5 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

as a tester, i don't know why people always say as a tester.

»
5 days ago, hide # |
 
Vote: I like it -19 Vote: I do not like it

WTF IS "Apologies for the previous announcement, the original statement was correct."?

worst round ever

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

    Incorrect announcement is entirely my fault: a question asked during the round made me believe that the statement was incorrect. This has nothing to do with the quality of the round.

»
5 days ago, hide # |
 
Vote: I like it +18 Vote: I do not like it

WHY ARE THE PROBLEMS SO HARD. Like you can see C has ~1k5 while D & E only has < 100 solved (up to 11h05)

»
5 days ago, hide # |
Rev. 2  
Vote: I like it +40 Vote: I do not like it

Testers forgot thought that they were testing a Div. 1 so they approved these problems

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

D is too hard for D :(

»
4 days ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

god i hate interactive problems

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

B was way too hard

I spent 1.5 hours on D and got TLE on pretest 3 using python

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

$$$B2$$$ is a good problem, but need to be very careful with implementation and time of the solution. $$$C$$$ is so much easier, it's basically the diameter finding algorithm.

100 solves on $$$D$$$ and $$$E$$$ is crazy.

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

Finally a contest with an interactive C

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

Got absolute cooked

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

nlog^2n intended for E?

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

Nice B1. Thanks.

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

loved the problems; especially D

»
4 days ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

who else remembered the tree diameter algorithm from Antti Laaksonen's book for C?

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

What the hell even is B2

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

COOKEDFORCES

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

maybe testers opinons about a problem being too hard matters...

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

how the hell do you solve B2, C is exponentially easier, how do they have the same amount of solves

»
4 days ago, hide # |
Rev. 2  
Vote: I like it +9 Vote: I do not like it

the jump from c to d/e was insane

and am i crazy or was b2 significantly harder than c

»
4 days ago, hide # |
Rev. 2  
Vote: I like it -22 Vote: I do not like it

What in the world was D?

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

    How are you so bad at cheating that you don't realize you can reuse B2 for B1? :sob:

    • »
      »
      »
      4 days ago, hide # ^ |
       
      Vote: I like it -80 Vote: I do not like it

      Buddy, there are people who are not here for the rank but solve questions for the approaches, I get where you are coming from due to the high amount of cheaters, there are ways to find them rather than just blindly pointing fingers at everyone, in this for more than 3 years now so have seen alot.

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

literatureforces C, B2 was too tough imo

»
4 days ago, hide # |
Rev. 2  
Vote: I like it +5 Vote: I do not like it

I gave up on B2 , solved it 1 min after contest when i re-tried it in the last 30 mins . hate my life :(

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

Nice contest

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

i'm usually pretty good at magic tiles

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

My solution for D:

First, disregard the statement about $$$2$$$ columns, these are just some random intervals. Remove any interval that is inside another interval. Split the intervals into connected components. Notice that any point is covered by at most $$$2$$$ intervals.

Each interval has at most $$$4$$$ possible states in the final solution: either cut or keep the left part and same for the right part. Say we processed the first $$$i$$$ intervals. There are $$$2$$$ solutions we should keep: the one where interval $$$i$$$ was not cut on the right and the one where it was cut. This allows us to extend to interval $$$i+1$$$ (there are like $$$4$$$ possible solutions of which we need to keep $$$2$$$). When multiple solutions are available, sort them in decreasing order and compare them lexicographicaly. The bigger one is the one you want.

If you implement this with multisets (I think maps work too but didn't check) then you get something like $$$O((N+M)^2*\log(N+M))$$$ which somehow fits in $$$4$$$ seconds (my solution takes $$$2.1$$$).

I think there are better ways to solve this though

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

    I think this solution is $$$O((N+M)^2)$$$ with no log factor. You're doing $$$O(N+M)$$$ insertions and $$$O(N+M)$$$ comparisons; insertions are $$$O(\log (N+M))$$$ and comparisons are $$$O(N+M)$$$ (even though searching for a single element takes $$$O(\log (N+M))$$$, you can traverse the entire tree in $$$O(N+M)$$$ time, not $$$O((N+M) \log (N+M))$$$ time).

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

    Thank you bro

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

My brain is offline

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

Good contest

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

easy C, hard B2

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

Problems D,E and F have no business in Div.2 round.

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

Is it just me or this contest was genuinely hard for a div.2 round?

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

    It was hard for me too.I could only solve A,B1 and C.I have seen way easier div 2s both in practice and live.

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

      This contest was actually tough even on an absolute scale. Could solve only A and B1 (don't really like interactive problems). The last time I solved 2, my rating decreased by 27, this time it increased by 21.

»
4 days ago, hide # |
 
Vote: I like it +1 Vote: I do not like it
»
4 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Thanks for contest and interesting tasks!

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

Bruh why are the proplems so hard (I didn't participate)

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

Bro WTFF THIS ROUND WAS LIKE SO LESS POINTS LIKE WHO MAKE B2 THAT MUCH HARD with 750 points GUYS IT'S DIV 2 NOT 1 SHOW MERCY MAN like wtf

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

IMO this was one of the hardest Div.2 rounds in terms of difficulty distribution.

A was a good standard A problem, and B1 was also reasonable, but the jump from B1 to B2 was quite large. B2 was not just a harder version; it required a completely different level of observation and understanding of the structure.

C was an interesting problem, especially because of the interactive nature, but it was still within the expected range of a Div.2 C.

The main issue was D. Magic Tiles felt more like a serious algorithmic problem rather than a typical Div.2 D. The combination of compressed input, huge coordinate range (10^18), and the need to construct a compressed optimal answer made it a very heavy problem for a 2-hour Div.2 contest.

E was also a very interesting but difficult problem. The LCM and divisibility observations required a strong mathematical insight.

Overall, I liked the problems because they were creative and educational, but I think the difficulty curve was too steep after B1. The gap between B1/B2 and D was much larger than what I usually expect from Div.2. For many participants, the contest probably became a race of solving A+B1+B2+C rather than gradually progressing through the problems.

Still, great round and very high-quality problems.

»
4 days ago, hide # |
 
Vote: I like it +67 Vote: I do not like it

Some solution sketches:

A: No operation can remove the first or last elements, and all remaining elements can be removed (by performing an operation on the element we want to remove, the first element, and the last element). Thus, the answer is the GCD of the first and last elements.

B: Fix k and suppose we will sell carrots with length $$$x$$$. To start, let's figure out how many carrots of length $$$x$$$ we can create by splitting a carrot of length $$$l$$$. We can make a few straightforward observations:

  • The number of carrots of length $$$x$$$ we can create is at most $$$\lfloor l / x \rfloor.$$$
  • Since each operation can at most double the number of carrots we have, $$$k$$$ operations will split a single carrot into at most $$$2^k$$$ carrots at the end. This means we can create at most $$$2^k$$$ carrots of length $$$x$$$ from one starting carrot.
  • Additionally, to achieve $$$2^k$$$ carrots of length $$$x$$$, the starting carrot must have length exactly $$$x \cdot 2^k$$$ (since the total length of the carrots at the end is the same as the length of the starting carrot). Otherwise, we can do no better than $$$2^k - 1$$$ carrots of length $$$x$$$.

This tells us that we can create at most $$$\min \left( \lfloor l / x \rfloor, 2^k - 1 \right)$$$ carrots of length $$$x$$$ from a single carrot, plus one extra carrot when the length is equal to $$$x \cdot 2^k$$$. This bound is achievable by performing cuts of length $$$2^{k-1} x, 2^{k-2} x, \cdots, 2x, x.$$$

In the easy case, with $$$k = 1$$$, this tells us that if our carrot length is $$$x$$$, the number of carrots we sell is equal to the number of carrots starting with length at least $$$x$$$ plus the number with length exactly $$$2x$$$. We can compute this efficiently for each $$$x$$$ in $$$O(N)$$$ time.

In the hard case, carrots of length between $$$x$$$ and $$$2x-1$$$ contribute $$$1$$$ ending carrot each, carrots between $$$2x$$$ and $$$3x-1$$$ contribute $$$2$$$ each, and so on, until all carrots with length at least $$$(2^k - 1) x$$$ contribute $$$2^k - 1$$$, except that carrots with length $$$2^k x$$$ contribute $$$2^k$$$.

We can iterate over $$$k$$$, and for each $$$k$$$, iterate over $$$x$$$. Using prefix sums, we can count the number of carrots whose lengths fall in each of the intervals described above (e.g. $$$x$$$ to $$$2x-1$$$, $$$2x$$$ to $$$3x-1$$$, etc) in $$$O(1)$$$ time per interval. This takes $$$\frac{n}{x}$$$ queries for each $$$x$$$, and summing over all $$$x$$$ gives a total complexity of $$$O(n \log n)$$$ for a fixed $$$k$$$.

Then, note that when $$$k \gt \log n$$$, taking $$$x = 1$$$ is sufficient to cut a carrot of length $$$l$$$ into $$$l$$$ pieces, which is the best we can do. Thus, for large enough $$$k$$$, the answer is just the sum of the entire array, which implies that we only need to do the computation described above for the smallest $$$\log n$$$ values of $$$k$$$. Thus, the total complexity is $$$O(n \log^2 n)$$$.

C: A well-known algorithm for finding a diameter of a tree is to root the tree arbitrarily and find the furthest vertex from the root; call this vertex $$$v$$$. Then $$$v$$$ must be one endpoint of a diameter; we can find the other endpoint by finding the furthest vertex from $$$v$$$.

We can execute this algorithm using the provided queries. Let $$$d$$$ be the largest distance between any two vertices we've found so far. Then, to find the furthest vertex from the root, maintain $$$d$$$ and a vertex with distance $$$d$$$ from the root. For each vertex, check if its distance is at least $$$d+1$$$, and increment d while this is true. In the end, the last vertex that caused us to increase $$$d$$$ is the furthest from the root.

Now, reroot the tree at the vertex found above and apply the same algorithm, without resetting $$$d$$$. The furthest vertex from the new root is the other endpoint of our diameter.

To bound the number of queries, note that each query causes us to either increment $$$d$$$ or to move on from a vertex we're currently checking. Since the diameter of the tree must be at most $$$n$$$, we do fewer than $$$n$$$ queries that increment $$$d$$$, and in each of our two iterations, we need to handle $$$n-1$$$ vertices each. The total number of queries is thus less than $$$3n$$$, so we're good to go.

D: First, note that the scoring function just means we want to lexicographically maximize the list of segment lengths when they're sorted in descending order.

Observe that if an interval in one column is contained within an interval in another column, we can ignore the first interval (because if we were to use any segment of it, we could achieve at least as high a score by instead using the corresponding segment of the second interval). This reduces the problem to the case where no interval contains another.

Index the endpoints of the segments and let dp[i] be the lexicographically largest list of segment lengths we can achieve before reaching the i'th endpoint. Iterate over $$$i$$$ in increasing order. Note first that if $$$i$$$ both the starting point of one segment and contained in another, the next segment we add should come from the segment starting at $$$i$$$, as if we wanted to use the other segment, we could do better by starting it before position $$$i$$$. Thus, given $$$i$$$, the segment we want to start from is uniquely defined.

Then, to transition, we should either use the full segment or the part of the segment until the starting point of the next segment in the other column. This gives us two transitions from each of the $$$O(N+M)$$$ states. We can compare two sequences in $$$O(N+M)$$$, so each transition takes $$$O(N+M)$$$ time to process, giving a solution in $$$O((N+M)^2)$$$ in total.

The one catch is that storing the entire DP table consumes $$$O((N+M)^2)$$$ memory, which is too much. However, all of our transitions take us to the next starting/ending point in one of the columns, so we only need to maintain $$$O(1)$$$ states at a time. Thus, our solution works in a total of $$$O((N+M)^2)$$$ time and $$$O(N+M)$$$ memory, which is enough to solve the problem.

E: First, observe that the answer must be a power of a prime. Indeed, if $$$k$$$ is not a prime power, then when we write $$$k$$$ as a product of prime powers, anything divisible by $$$1, \cdots, k-1$$$ must be divisible by each of the constituent prime powers, and thus by $$$k$$$ itself.

Now, suppose we want to find $$$l$$$ and $$$r$$$ satisfying $$$f(l, r) = x$$$ for some prime power $$$x$$$. We might as well make our subarray as large as possible, so either $$$l = 0$$$ or $$$a_{l-1}$$$ should be a multiple of $$$x$$$, and likewise either $$$r = n-1$$$ or $$$a_{r+1}$$$ should be a multiple of $$$x$$$. In other words, the subarray we choose should be an interval between two elements of $$$a$$$ that are multiples of $$$x$$$ (with no multiples of $$$x$$$ in between them).

Iterate over the elements of $$$a$$$ from right to left and say our current position is $$$p$$$. We'll maintain an array $$$nxt$$$ where $$$nxt_i$$$ is the position of the next multiple of $$$i$$$ with position greater than $$$p$$$ in $$$a$$$. Then, if $$$nxt_i \gt nxt_j$$$ for all prime powers $$$j \lt i$$$, we can set $$$l = p+1$$$ and $$$r = nxt_i - 1$$$ to get an array with $$$f(l, r) = i$$$. Storing $$$nxt$$$ in a segment tree lets us perform these queries in $$$O(\log n)$$$.

By the above observation, it suffices to only check cases where $$$a_p$$$ is a multiple of $$$x$$$. As we iterate over $$$p$$$, we'll check the above condition for all prime powers that divide $$$a_p$$$, then we'll update $$$nxt$$$ accordingly. At the end, we'll check the condition for all prime powers to handle the subarrays starting at index $$$0$$$.

The number of prime powers dividing $$$n$$$ is bounded by $$$\log n$$$, so at each index we perform $$$O(\log n)$$$ updates and queries. Our total complexity is therefore $$$O(n \log^2 n).$$$

F: We perform tree DP. For each vertex $$$v$$$, we'll compute the minimum possible sum of costs in the subtree of $$$v$$$ for each possible value of the sum of $$$x_u$$$ over the subtree of $$$v$$$.

In the base case, the cost of a leaf is always 1, and depending on the starting value, $$$x_v$$$ can be $$$1$$$, $$$-1$$$, or both.

To transition, we need to combine this data over all subtrees. To do this, we'll use the slope trick: for each subtree, we'll store the minimum possible subtree sum and its cost, plus an array containing the differences in costs when we increase the balance by 2 (for any subtree, the parity of the balance must be equal to the parity of the number of vertices in the subtree). It can be proven by induction (using facts from the rest of the solution) that these slope arrays are always increasing.

To combine two arrays, we just merge their slope arrays and sort in increasing order. Then, if the root vertex of our subtree has value 1 or -1, we can just add or subtract 1 from the minimum possible subtree sum. If the root has value 0, then we subtract 1 from the minimum possible subtree sum. Now, the cost of achieving slope $$$x$$$ is equal to the minimum cost of achieving slope $$$x-1$$$ or $$$x+1$$$; this can be simulated by adding a $$$0$$$ to the set of slopes. Then, we update by adding -2 to the slope over the interval where the subtree sum is negative and 2 to the slope over the interval where the subtree sum is positive.

These operations can be handled efficiently using a treap. Treaps can merge subtrees of sizes $$$n$$$ and $$$m$$$ with $$$n \gt m$$$ in $$$O(m \log (n/m))$$$ and can perform range updates in $$$O(\log n)$$$, and this is enough to achieve a total complexity of $$$O(n \log n).$$$

If you don't have a treap library on hand, another approach is to maintain two sets for slopes greater than or less than $$$0$$$, eliminating the need to split before performing range updates. We can maintain a fixed tag for each of the two sets in order to perform updates over the whole set. This approach has $$$O(n \log^2 n)$$$ complexity.

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

Thanks everyone for participating in Codeforces Round 1117 (Div. 2). Although it was initially difficult to understand from the editorial when I first participating in Codeforces contests. However I found that once I got used to it, the explanations felt very easy to understand, accurate, and highly academic.

We should read the hint and solution before reading code (Sorry for my bad English)

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

The < and > operators of std::vector can conveniently perform lexicographical comparisons.

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

D problem is best problem in this contest

»
4 days ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

wallahi I got cooked

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

this contest made me ragequit

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I received a plagiarism warning for submissions 388806569 (2258B1) and 388825898 (2258C). I would like to clarify that I did not copy these solutions from the mentioned users. I solved both problems independently during the contest. The approaches I used are standard/direct approaches for these problems, which may explain the similarity. I am happy to provide an explanation of my reasoning or any additional information needed for review.

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i was late for this contest but i checked questions and it was really good. Turkish people do more contest like this. and specially for div 3 and div 4 for beginners.

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

acc

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

@cadmiumky, I received a plagiarism warning for submission 388819264 (2258C). I would like to clarify that I did not copy this solution from any of the mentioned users. I solved it independently during the contest. The approach used is the standard adaptive-query technique for finding the diameter in an interactive setting (as described in the editorial), and the resulting code is quite short, so there is limited room for stylistic variation which likely explains the similarity across many submissions. I am happy to provide my code or any additional information needed for review.

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello Codeforces team,

I received the system message regarding my submission 388802642 for problem 2258B1, which significantly coincides with someone.

I want to clarify that both accounts belong to me. I recently created the second account with my different gmail id and mistakenly participated in the contest using both accounts. I submitted the same solution from both accounts, which is why the submissions are identical.

I was not aware of that using multiple accounts in the same contest is against the rules. This was my mistake, and I apologize for it. I will use only one account for future contests and will not repeat this.

Thank you

»
3 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello Codeforces Team,

I received the plagiarism warning regarding my submission 388804450 for Problem 2258C. I want to clarify that I wrote my solution independently and did not copy or communicate with the other contestant.

I understand that my implementation is similar to another submission. However, the underlying approach is based on a standard tree-diameter technique using distance queries, which predates this contest.

For reference, similar techniques were publicly available before the contest: * 2020 write-up on finding the diameter of a hidden tree using distance queries: https://anonymous3141.github.io/blog/2020/Tree-Graphs/ * “Finding the diameter of a tree with distance queries”, published on arXiv in September 2025: https://arxiv.org/abs/2509.23326

I am providing these sources to show that the underlying approach was publicly known before the contest and could be independently derived. I did not use the other contestant's code or communicate with them. I respectfully request that my submission be reviewed in this context.

Thank you.

»
2 days ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

b1 i solved this way only freq[x] and freq[2x] matter and using binary search easy way https://pastecode.io/s/3phi2vwi

»
32 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can somebody give the optimal solution of b1

  • »
    »
    32 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    My O(N log N) approach for Problem B:

    Intuition:

    When we consider any even value x present in the array, the maximum operations we can perform on it is bounded by m >= x / 2.

    If we fix this operation, any element already greater than or equal to x / 2 will contribute to the valid subset.

    We sort the array initially so that for each valid even number x, we can find the count of elements >= x / 2 in O(N) using a two-pointer pass.

    We also add the frequency of x itself and compare across all candidate even numbers to get the maximum possible count.