Top Comments

Easy problems in abc are designed to require no algorithm but programming language.

AI masters programming languages very well and also know a little about algorithms.

It's normal for AI to solve these problems, or AI would be too weak.

+47

I like when FBI tests the round ! I feel more secure

Cap. There's no one in the ranklist who solved exactly A, C and D.

On Nummer_64IOI 2024 Teams, 13 hours ago
+36

Serbia's team:

  1. Miloš (wxhtzdy) Milutinović — 2nd time at IOI(Silver IOI 2023), 0 attempts left

  2. Nemanja (NemanjaSo2005) Majski — 2nd time at IOI(Bronze IOI 2023), 0 attempts left

  3. Mihailo (prokulijander) Jančević — 1st time at IOI, 0 attempts left

  4. Uroš (urosk) Kostadinović — 1st time at IOI, 1 attempt left

On dpsingh32codeforces grind, 17 hours ago
+32

6-8hours? DAILY? brother calm down you'll be burnt out in a week tops.

On Nummer_64IOI 2024 Teams, 46 hours ago
+31

Uzbekistan's team:

  • Asilbek Sunnatov (Sunnatov) — 2nd time at IOI, 1 attempt left

  • Husanboy Mansuraliev (Husanboy) — 2nd time at IOI, 0 attempts left

  • Ulugbek Rahmatullaev (heaven2808h) — 1st time at IOI, 2 attempts left

  • Mardon Hazratov (MardonbekHazratov) — 1st time at IOI, 0 attempts left

I feel scared that AI will be stronger than many people.

Why is today's G only worth 575 points? I think it is as hard as last round's G, which is 650 points. (and the statistics agrees with me too!)

On Nummer_64IOI 2024 Teams, 16 hours ago
+28

Macedonia:

  • Blagoj Rujanoski Stojanovski (Blagoj) $$$-$$$ 2nd time at IOI, 2 attempts left

  • Damjan Davkov (damjandavkov) $$$-$$$ 2nd time at IOI, 2 attemts left

  • Viktor Maksimoski (VMaksimoski008) $$$-$$$ 1st time at IOI, 3 attempts left

  • Sofija Velkovska (coolplum) $$$-$$$ 2nd time at IOI, 0 attempts left

On Nummer_64IOI 2024 Teams, 15 hours ago
+28

Bro literally cooked with his lockpicking skills

On tickbirdWhat if, 13 hours ago
+26

Dude, stop posting the same garbage over and over again.

If you don't enjoy CP, just stop. Simple.

One of the ways to fix it is to add the target pragma AFTER the STL includes. This should make your code compile, but a lot of code would simply not be optimized, so use it at your own risk.

It is not necessary to leave the whole STL without optimization, you only need the place where the error occurs to be before any target pragma. If you look closely at the output, you will see that the error occurs at C:/Programs/gcc13-64-winlibs/include/c++/13.2.0/bits/allocator.h:184:7. So you need to add only #include <bits/allocator.h> before the pragmas to make your code compile.

this code compiles on g++-13 in custom test
On amin_2008EGOI 2024 Teams, 19 hours ago
+25

Romania:

  • Iulia-Ela Morariu (iulia.ela.morariu) — 1st time, 5 attempts left
  • Ana-Maria Petcu (6ana6) — 1st time, 1 attempt left
  • Ioana Mihaela Pașca (rockoanna) — 1st time, 1 attempt left
  • Elisa Ipate (elisaipate) — 1st time, 1 attempt left
On amin_2008EGOI 2024 Teams, 18 hours ago
+25

Team Georgia:

• Nino Chkaidze (NintsiChkhaidze) 3rd time, 0 attempts left

• Gvantsa Khvedelidze (gvancak) 3rd time, 2 attempts left

On amin_2008EGOI 2024 Teams, 13 hours ago
+25

Average of max ratings can be a misleading metric, since usually a master and a newbie are stronger than 2 cyans. Instead, something like the ;teamrate command implemented by TLE would be better.

On amin_2008EGOI 2024 Teams, 18 hours ago
+24

NintsiChkhaidze will win EGOI 2024!

On amin_2008EGOI 2024 Teams, 12 hours ago
+24

Ukraine Team on EGOI2024:

  • Kseniia Strelbytska(ksu_) — 1st time, 2 attempts left
  • Daria Perekopska(perekopska.d) — 1st time, 2 attempts left
  • Yunna Kheifets(YKheifets) — 1st time, 0 attempts left
  • Viktoriia Lavrova(lavvikta) -1st time, 1 attempt left
On Nummer_64IOI 2024 Teams, 14 hours ago
+23

Rules are meant to be broken (brute forced)

On PhysicalHappy Children day!, 46 hours ago
+20

I am 25 years old

+20

Vladosiya back to CM

On Pui.PuiFree Palestine, 35 hours ago
+20

MikeMirzayanov please make this place out of such things.

i dont see why they should remove it either, its not like its disallowed

On norOn implementing FFT, 21 hour(s) ago
+20

Hi! I'm glad you liked the post and hope you learnt something new from it.

On comments
On amin_2008EGOI 2024 Teams, 17 hours ago
+20

orz

wasa855 LJC00118 xay5421, Asia East, China, Peking University.

On Nummer_64IOI 2024 Teams, 15 hours ago
+19

Blagoj orz

On 1.618034Ratism or what??, 44 hours ago
+18

Solution :

My O(max(a) * log(max(a))) submission passes for E, maybe you didn't remove duplicates from the array?

+18

(I think that if you send 2 or more accepted submissions then the last one is the penalty giving one).

Actually, every submission after the first accepted one does not count, so the penalty is (the number of wrong submissions before the first accepted submission) * 10 + (the time in minute the first accepted submission was made). This is why you can freely submit multiple solutions if you have any doubt in your previous accepted solution without worrying about the penalty in Educational / Div. 3&4 rounds (as opposed to normal Div. 1 or 2 rounds where the earlier solutions become WA penalty).

On amin_2008EGOI 2024 Teams, 17 hours ago
+18

orz

On Pui.PuiFree Palestine, 35 hours ago
+17

I think this is not a place to get political.

It's quite fun seeing I am blue with the rating of 2007 :)

but I believe it will update soon.

Managing different account.

well, well....

On Pui.PuiFree Palestine, 35 hours ago
+16

If you seek attention, then twitter is a better place for all these political topics. Leave this platform away from such stuffs. Nothing gonna change by such posts.

I will use the power of induction, going over the number of vertices in the tree.

The base is immediately obvious for n = 1 or n = 2.

Consider a vertex v != root. If we choose some set of leaf nodes L = {l1, l2, ..., lk} in its subtree, how many bridges do we remove? This number equals to the size of the union of edges of all paths from li to v, plus some number C, which does not depend on leaves in L.

Actually, C depends only on other leaf nodes we chosen — the ones not in L. It can be shown that C equals to the number of remaining bridges on the path from v to root after we choose all leaves do not belong L.

This means we can choose some leaf nodes outside of v's subtree, and then optimize leaves in Lindependently from others, if |L| = const(if their number remains constant). By inductive hypothesis for v's subtree, greedy is the optimal way.

Suppose we have some solution which is not greedy. Let's show that there is a vertex v, which subtree solved non-greedy (and we can make it better). Just take 2 leaves: l1, which will be taken in greedy solution, and l2, which was taken instead of l1. Choose v = LCA(l1, l2).

P.S. May be there is some inaccuracy in my proof, such as deg(root) = 1 condition in the problem, but induction does not use it. We need this condition only to find out that we should connect root with 2k-1 leaves, so there is no problem.

On amin_2008EGOI 2024 Teams, 20 hours ago
+16

Switzerland:

  • Vivienne Burckhardt (_Avocado_) — 4th time, 0 attempts left

  • Hannah Oss (hannahhhhh) — 3rd time, 0 attempts left

  • Hongjia Meng — 2nd time, 3 attempts left

  • Myriam Faltin — 1st time, 4 attempts left

On Nummer_64IOI 2024 Teams, 19 hours ago
+16

anpaio is a 9th grader at the time of this IOI 😁

On Nummer_64IOI 2024 Teams, 15 hours ago
+16

otarius will win IOI 2027!

Maybe you should ping the author chromate00 to check this.

A simpler solution for problem E that doesn't require graphs:

Let's say we merge using $$$h$$$ if the $$$h$$$ dimension of the two rectangles are the same and we make a new rectangle overlapping these two edges.

Consider places where we "switch" between the two dimensions when we merge (those $$$i$$$ where we merge $$$i-1$$$ and $$$i$$$ using $$$h$$$, but merge $$$i$$$ and $$$i+1$$$ using $$$w$$$, or the other way round). WLOG, suppose that we merge $$$i-1$$$ and $$$i$$$ using $$$h$$$, then it's easy to see that $$$h_{i-1}=h_i$$$ and $$$w_i=w_{i+1}$$$.

We can observe that whatever we do before $$$i$$$, the rectangle that is being merged into $$$i+1$$$ is always $$$(h_i,w_{i+1})$$$. Therefore, we denote $$$g_{i,0/1}$$$ which means the maximum place we can reach if we start with $$$(h_i,w_{i+1})$$$ or $$$(h_{i+1},w_i)$$$ and start merging from rectangle $$$i$$$.

In order to get the value of $$$g$$$, we can simply find the next place where we have to switch, and from the place on, we can use the $$$g$$$ we have already calculated to get the answer. This place can be found easily using binary search.

There is only one exception, where we can use both dimensions to make a move. However, in this case, the rectangle we currently have and the next one must be exactly the same. Therefore we can simply denote $$$f_i$$$ meaning the answer if we start with $$$(h_i,w_i)$$$ and merge from $$$i$$$. The way to find $$$f$$$ is similar to $$$g$$$, and so is the way to find the actual answer.

On amin_2008EGOI 2024 Teams, 11 hours ago
+15

EGOI team of Türkiye:

  • Duru Özer (Weobe) — 3rd time at EGOI, 0 attempts left

  • Bergüzar Yürüm (berr) — 3rd time at EGOI, 0 attempts left

  • Elif Başak Keleş (elotelo10) — 2nd time at EGOI, 2 attempts left

  • Nehir Karatopcu (DangerNoodle7591) — 3rd time at EGOI, 3 attempts left

I have consulted the coordinator for a way to fix this. If I can swap out the model solution to the $$$\mathcal{O}(n {\log_2}^2 n)$$$ tester solution that is guaranteed to work, then at least the problem becomes fine. I am unsure if this is possible however. I will keep you updated.

On amin_2008EGOI 2024 Teams, 37 hours ago
+14

Strong!

On amin_2008EGOI 2024 Teams, 15 hours ago
+14

NintsiChkhaidze will win EGOI 2024!

On amin_2008EGOI 2024 Teams, 15 hours ago
+14

NintsiChkhaidze will win EGOI 2024!

$$$B$$$ is a great DP problem , it's a shame that I couldn't solve it during contest by not being quick enough to debug but solved after the contest

On 1.618034Ratism or what??, 44 hours ago
+13

who hates

Yeah. That is the point of ratism

On PhysicalHappy Children day!, 43 hours ago
+13

cringe ahh post

Yes, it seem, this tickbird is made for leaving comments only. Here is his alt jinsu

+13

In Div. 3 the most important thing is the number of solved problems. If 2 participants have the same number of problems solved, then a "penalty" is computed for each of them. The penalty is the sum over the solved problems of the number of minutes from the begining of the contest up to the accepted submission (I think that if you send 2 or more accepted submissions then the last one is the penalty giving one).

Penalty can also be accumulated by making wrong submissions, i. e. 10 minutes/penalty points per submission. Thus if you submit 3 wrong submissions and a correct one after 50 minutes from the start of the contest, your penalty will be $$$3 * 10 + 50 = 80$$$ for this problem. Do this calculation for each problem, sum the penalty and you get your total penalty.

It is best to have small penalty (i. e. solve problems fast with less errors).

On Nummer_64IOI 2024 Teams, 15 hours ago
+13

Blagoj orz

It's actually confirmed that they used AI, because if you see their submissions such as https://atcoder.jp/contests/abc355/submissions/54073783 and https://atcoder.jp/contests/abc355/submissions/54073778, it says "Generated by gpt4-o" at the top.

Some local environments, like CodeBlocks, tend to mostly give your program zero-filled memory on allocation. So the bugs like uninitialized variables are less visible then.

Ignoring the difficulty, I think this round is more edu than edu round.

O(n) problem D in only 24 lines

UPD: I compressed my code further and I'm surprised to find that I now have the shortest correct solution for the problem.

+11

it's the penalty for a wrong submission in this round

+11

You can solve all problems here: https://oj.uz/problems/source/652

+11

Did he do it on purpose?

I asked because......

Thanks for reply!
Exactly because of it's almost not a problem for ARC or above, serious competitors are almost not care this situation in the difficult round (and I also don't hope to be do hard banning of AI).
But in ABC, the situation is different. In ABC356, fastest ABCD gets about 1400perf so every green or below coder "shold" use this method. From Japanese community, it seems this strategy problem and "lose to ChatGPT" itself demotivated them and some of community members think this isn't healthy.
In addition, the thing that ABC focuses on education and guideline rather than competition makes this problem more complex, then switch ABC to more competitive (for example, make them more ad-hoc) is not a solution...

GLHF!

On amin_2008EGOI 2024 Teams, 13 hours ago
+11

Macedonia:

  • Jovana Trifunoska (kicika) $$$-$$$ 3rd time at EGOI, 0 attempts left

  • Atina Ruvinova (AtinaRu) $$$-$$$ 3rd time at EGOI, 1 attempt left

  • Sara Stefanovska (sara2006) $$$-$$$ 3rd time at EGOI, 1 attempt left

  • Antonela Vladeva (dejzi_rose) $$$-$$$ 1st time at EGOI, 1 attempt left

Here's what happened: The educational round's rating was calculated first and then div2's ratings. However, when Div 2 was happening the ratings of educational were not calculated, so they participated in div2 as candidate masters. But when it comes to calculating ratings of div2 they've already become masters after the educational round was considered.

On 1.618034Ratism or what??, 43 hours ago
+10

maybe its all to get more contributions

On Nummer_64IOI 2024 Teams, 29 hours ago
+10

What the fuck valeriu you're a 9th grader at the time of the last IOI, tibinye is, like 10th or 11th grade or something. God

Yes, that is definitely the cause of the problem. Essentially what's happening is that when you execute code locally most arrays are initialized to 0 because the kernel always provides 0-initialized memory (the only case in which this will not happen is if you stop using a variable before declaring another one), while the cf judge does not necessarily do that. You can read more about this here.

Bro chill i mean... It happened for everybody and it is impossible that codeforces won't notice such things so please, to everyone: stop posting useless blogs

As a tester, I tested

Problem setter, I don't know who you are, but I love you, you are amazing! =)

I laughed so hard when I solved problem C and read the problem statement of D =))))

Problem A is very ez, but was so satisfying to solve with clean c++ std. Pure joy =))

Problem A
On estoy-re-sebadoThe strongest CMs?, 35 hours ago
+9

That means I am one of the strongest unrated coders.

On Nummer_64IOI 2024 Teams, 15 hours ago
+9

orz

Okkayy... Suppose you have a gap like: [4, -1, -1, -1, 3]

  • Now, consider two numbers outside the gap, 4 and 3, as 4 >= 3, the gap: [4, 2, -1, -1, 3] [4 >>= 1 means dividing by 2, so 4/2 is 2]
  • Now, consider 2 and 3, 3 >= 2, then: [4, 2, -1, 1, 3]
  • Then, 2 >= 1, then [4, 2, 1, 1, 3]
  • If the filled-gap is valid, continue to next gap!
  • But in this case, this is invalid, which will be checked on later step and print -1

Consider the same gap with an extra -1! Then finally we will get [4, 2, 1, -1, 1, 3]

  • Here 1 >= 1, but here we cannot divide 1 by 2, because by rule, all a[i] >= 1, so multiply by 2, then we are getting [4, 2, 1, 2, 1, 3].
  • This is correct solution!

Now, imagine different gaps and try yourself to fill it up!

please, why my code wrong (problem B)

include <bits/stdc++.h>

using namespace std;

long long cases, m, n;

int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

cin >> cases;
for (int t = 1; t <= cases; t++)
{
    cin >> n >> m;

    if (m == 0) cout << n << "\n";
    else {
       int len = __lg(m + n), sum = m + n, lim = 0;
       for (long long i = (1LL << len); i >= 1; i = i >> 1) {
         if ((sum & i) > 0 && (n & i) == 0) {
          lim = i;
          break;
         }
       }
       for (long long i = 1; i <= lim; i = i << 1) {
         n = n | i;
       } cout << n << "\n";
    }
}

return 0;

}

I got what you were trying to do , and i myself got the intuition maybe we can find the largest and insert half on each of its side , but i wasnt particularly able to get a conclusive proof to why this should work , I cannot think of a testcase at particular , but it just seemed to me that , there may exist a case where this solution wont work , do you have any proof as such why was this working , it will help me a lot in maybe understanding your thinking better or anything in such .

Thank you in advance.

Damn, that's right. My god, I completely forgot about it

dkhve is the handle of Khvedelidze.

On estoy-re-sebadoThe strongest CMs?, 38 hours ago
+8

Ok so I am not only the one facing this problem in the last edu contest I got pupil badge but my name colour is still gray.

I think allowing AI is not a problem. Firstly, anyone can plug a given problem into ChatGPT, so its not giving an unfair advantage to particular users. Secondly, AI can't solve any problems with even somewhat challenging algorithmic thinking, so it really doesn't impact any serious competitors.

ok I just initiated the prev and next in the struct node with NULL !! I really have no idea what is the problem and why this fixes it !!

Before
After

Your push code relies on next and prev being equal to NULL if they aren't actually pointing to anything (ex if(s->prev)). However, if next and prev are initialized to random values leftover in memory, this logic no longer holds. So that's why you need to set them to NULL initially in order for your logic to make sense.

+8

As the problems change and adapt, we too must become stronger and evolve into more superior problem solvers

             (\__/)
              (UwU)
          _ノ ヽ ノ\_ 
        / `/ ⌒Y⌒ Y  \
        (  (三ヽ人  /  |
        | ノ⌒\  ̄ ̄ヽ  ノ
         ヽ___>、__/
            |( 王 ノ〈 
             /ミ`ー―彡\ 
            / ╰    ╯ \

F using binary search and segment tree. For a x, we need to know the leftmost element having absolute different with element to it's left > k. In the same way we will find the rightmost element having absolute different with element to it's right > k. Now we have 2 indexes a and b. The answer will be no of element in the range [a, b] which are still part of S. Sorry for my bad English.

Codeforces also estimates the ratings by people who solved the problem.

You should swap line 67 and line 68 of your code.

On Nummer_64IOI 2024 Teams, 14 hours ago
+8
On expolsion673Congrats to Israel, 12 hours ago
+8

**Free Palestine !**

On tickbirdWhat if, 12 hours ago
+8

Maybe it's not. But seeing the same person complain about the same things making the same blogs is definitely not cool. Regardless of what aptitude you have, if you enjoy CP, you should continue doing it. And regardless of what aptitude you have, if you don't enjoy CP, you should stop doing it.

It's that simple. So I don't really see the point of many blogs instigating the same topics about self-loathing. I guess the community may also agree with me, seeing the downvotes. I'm sorry if it touches someone, but blogs like these are somewhat discouraging to newer codeforces participants.

On Galium123My friend have a problem, 11 hours ago
+8

man how many accounts do you have

On Hidden-NinjaProblem C topic list, 44 hours ago
+7

guessing problems :0

At first assume, that there are no repeating numbers.

First let's sort the array. Assume, we have following: $$$[1, 2, 4, 5]$$$. We are calculating following: $$$(2 / 1 + 4 / 1 + 5 / 1) + (4 / 2 + 5 / 2) + (5 / 4)$$$. Let's calculate it parenthesis by parenthesis.

Assume, current number is $$$x$$$. By dividing which numbers by $$$x$$$ we get $$$1$$$? Numbers $$$x, x+1, \dots, 2x - 1$$$. By dividing which numbers by $$$x$$$ we get $$$y$$$? Numbers $$$xy, xy + 1, \dots, (x+1)y - 1$$$. Let's instead of original array use array of occurences: $$$[1, 1, 0, 1, 1, 0, 0, 0, \dots]$$$, which means, there is one occurence of $$$1$$$, one occurence of $$$2$$$, zero occurences of $$$3$$$, etc. Let's build prefix sums $$$ps$$$ on this array. Now the required number is $$$ps[(x + 1)y] - ps[xy]$$$.

We need to iterate over all possible $$$y$$$. But aren't there too many of them? We don't need to have $$$xy > 10^6 = C$$$, because there will be only zeros in array of occurences. So $$$y \le \frac{C}{x}$$$. Number of iterations will be $$$\frac{C}{1} + \frac{C}{2} + \frac{C}{3} + \dots + \frac{C}{C} = C(\frac{1}{1} + \frac{1}{2} + \frac{1}{3} + \dots + \frac{1}{C})$$$. The expression in parenthesis is well-known. It is called harmonic series and is approximately equal to $$$\ln(C)$$$. So if we simply iterate over all $$$x$$$ and $$$y$$$ up to $$$\frac{C}{x}$$$ it will be $$$C \cdot \ln(C)$$$ time.

About repeating number. In straightforward implementation all pairs of repeated numbers will be calculated, but we need to calculate them left to right direction. To do it, we can simply subtract all extra pairs by $$$res -= \frac{cnt(cnt + 1)}{2}$$$.

On amin_2008EGOI 2024 Teams, 33 hours ago
+7

Italy:

  • Matilde Iannaccone (matilde) — 2nd time, 1 attempt left
  • Sofia Maragò (LaMatematica14) — 2nd time, 2 attempts left
  • Lavinia Tornaghi (laviniatornaghi06) — 3rd time, 1 attempt left
  • Serena Federici (madsere) — 2nd time, 0 attempts left
On amin_2008EGOI 2024 Teams, 30 hours ago
+7

Hungary:

Let's start with a well-known fact from number theory, also mentioned in the linked Wikipedia article: the "cool" numbers are 1, 2, 4 and $$$p^k$$$, $$$2p^k$$$ for all odd primes $$$p$$$ and positive integers $$$k$$$ (that is, the cool numbers are 1, 2, 4, 3, 9, 27, 81, ..., 5, 25, 125, 625, ..., ...).

What is, then, the number of cool divisors of a number $$$x$$$? I'll refer to this as the coolness of $$$x$$$, similarly to how the problem talks about the coolness of a set. If I write $$$x$$$ as the product of its prime factors:

$$$ x = 2^{k_0} p_1^{k_1} p_2^{k_2} \cdots p_s^{k_s}, $$$

then:

  • if $$$k_0 = 0$$$, then the coolness is $$$1 + k_1 + k_2 + \cdots + k_s$$$.
  • if $$$k_0 = 1$$$, then the coolness is $$$1 + 1 + 2(k_1 + k_2 + \cdots + k_s)$$$.
  • if $$$k_0 \ge 2$$$, then the coolness is $$$1 + 2 + 2(k_1 + k_2 + \cdots + k_s)$$$.

The fact that 1 is considered cool is annoying, so is the fact that 2 is different from other primes. We can get rid of the $$$+1$$$ at the beginning of each of these expressions by separately counting, for each query, the total number of sets we are summing over, and adding that number to the answer. As for the rest, the plan is as follows:

  • Initially pretend that the coolness of every number and set is $$$2(k_1 + k_2 + \cdots + k_s)$$$, calculate the answer using that.
  • Now pretend that the coolness of every number and set is $$$k_1 + k_2 + \cdots + k_s$$$. Solve the problem considering only odd numbers, since sets of odd numbers are the ones for which we initially used the wrong coolness. Subtract that from the answer.
  • Count the number of sets that we are interested in that contain at least one even number. Add twice that count to the answer.
  • Count the number of sets that we are interested in that contains exactly one even number, such that that even number is not divisible by 4. Subtract that from the answer.

That's a lot of subproblems. Let's look only at the first one, since the others can be solved by similar techniques.

Now we say that the coolness of a number $$$x$$$ is $$$2(k_1 + k_2 + \cdots + k_s)$$$, where $$$x = 2^{k_0} p_1^{k_1} \cdots p_s^{k_s}$$$. Similarly, the coolness of a set is the coolness of the product of its elements. Now, notice that because of how coolness is defined, the coolness of a set is also the sum of the coolnesses of its elements (**key observation**!).

Now we have a new problem yet again. We are given an array $$$c_1, c_2, \ldots$$$, where $$$c_i$$$ is the coolness of the number $$$i$$$. This array is known to us and not part of the input, and we can precalculate it once, at the beginning of the solution, not for each query. We want to find the sum of $$$\sum_{i \in T} c_i$$$ over all sets $$$T$$$ with size between $$$A$$$ and $$$B$$$ such that $$$T \subseteq \{L, L + 1, \ldots, R\}$$$.

For each $$$L \le i \le R$$$, $$$c_i$$$ contributes to this double-sum the same number of times. How many times? It's the number of ways to pick between $$$A - 1$$$ and $$$B - 1$$$ other elements to the set among the $$$R - L$$$ choices. In other words, the answer to the query is

$$$ \left[ \binom{R - L}{A - 1} + \binom{R - L}{A} + \cdots + \binom{R - L}{B - 1} \right] (c_L + c_{L + 1} + \cdots + c_R). $$$

For each query, we need to calculate these two sums fast. The second one is easy: at the beginning of our solution, we precompute the array $$$c_i$$$ and then its prefix sums.

How to do the first one? Let's denote

$$$ d_{i, j} = \binom{i}{0} + \binom{i}{1} + \cdots + \binom{i}{j}. $$$

To answer a single query, we need to know $$$d_{R - L, B - 1}$$$ and $$$d_{R - L, A - 2}$$$. Calculating all $$$d_{i, j}$$$-s takes too much time, however we only need to know $$$2T$$$ values over the entire solution.

How to effectively calculate these? Notice that

$$$ d_{i, j} = 2d_{i - 1, j - 1} + \binom{i - 1}{j}. $$$

This means that if we already know $$$d_{i, j}$$$, we can efficiently calculate $$$d_{i - 1, j - 1}$$$, $$$d_{i + 1, j + 1}$$$, $$$d_{i, j - 1}$$$ and $$$d_{i, j + 1}$$$. If we cleverly change the order of these $$$2T$$$ values we need to calculate, we can use these steps to move from one needed value to the next and only take $$$O(N \sqrt N)$$$ steps, where $$$N$$$ is the upper bound for $$$R$$$ and $$$B$$$, i.e. $$$10^5$$$. This is Mo's algorithm (which is sorting the test cases as well as square root decomposition). And that's the solution.


Sorry if this explanation turned out to be complex. The problem itself is complex (sum of products of weird things in statement), has many annoying details (such as 2 being different), and is at the end of the day a 2740 problem. I also left out some details (avoiding logs in the steps of Mo's algorithm).


May I ask why you thought the solution should involve precomputing, square root decomposition or sorting the test cases? Were they guesses based on constraints or something you saw when reading others' solutions?

In general I'd advise to not start from thinking "I need to do square root decomposition" or "I need to reorder the test cases". See this. After a certain level, this information is not helpful at the beginning of the problem solving process.

Look how different my process was: start from analyzing what this "coolness" value really is. Make the key observation. I ended up at all the things you mentioned in your question, but all those things came up at the end only.

Or more specifically, I paid no attention to any of that before it was clear the problem could be solved in polynomial time (looking at only the CodeChef statement, the obvious solution is exponential time). There is no point in thinking of reordering the test cases if you don't have a polynomial-time solution because reordering the test cases can't change an exponential solution to a polynomial one.

+7
On Normal_PeopleA meme from Div.2 949, 43 hours ago
+6

How is that relevant here ?

On amin_2008EGOI 2024 Teams, 37 hours ago
+6

_er than ever!

Simply rejudging the old submission leads to 1.2s too. It's just that library checker now use much better servers and also -march=native.

On Um_nikHow to read problem statements, 23 hours ago
+6

"After that reduction it is kinda known problem", which known problem is this ?

Edge coloring.

Do I need to generate the entire bipartite graph as defined above? The number of cycles in a complete graph with 14 nodes will be of the order of 14!, so I don't think it's even possible to generate the entire graph.

No. The big bipartite graph is only theoretical.

On amin_2008EGOI 2024 Teams, 15 hours ago
+6

NintsiChkhaidze will win EGOI 2024!

I am getting WA in 1 test case and TLE in 2. Looks like some edge case is not handled. Can someone take a look https://atcoder.jp/contests/arc179/submissions/54181150.

Consider $$$A=-4,2,3,3$$$, and $$$R=4$$$.