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

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

Автор Cocoly1990, 22 месяца назад, перевод, По-русски

Good... yes, good afternoon, Codeforces!

We are glad to invite you to take part in Good Bye 2024: 2025 is NEAR, which will start on 28.12.2024 17:35 (Московское время). You will be given 9 problems and 3 hours to solve them. One of the problems will be divided into two subtasks.

All the problems are authored by _istil and me.

In this round, we would like to say goodbye to the past bad memories. However, the point is we won't say goodbye to:

UPD: The score distribution is $$$500 - 1000 - 1250 - 1750 - 2000 - 2500 - 4250 - 4500 - (3000 + 2000)$$$.

UPD: as pointed out here, the official solution of 2053I2 - Ласковые массивы (сложная версия) is wrong. We are not sure that the problem is solvable with the current constraints. We will decide how to deal with this issue within tomorrow.

UPD: the problem I2 was removed from the official contest. Its statement has been corrected for future use. The affected participants have been unrated from the contest.

UPD: Congratulations to the winners!

  1. jiangly
  2. ecnerwala
  3. Benq
  4. Egor
  5. Radewoosh
  6. Petr
  7. Ormlis
  8. ksun48
  9. Nachia
  10. EnofTaiPeople

Мы рады сообщить, что компания NEAR поддержала проведение раунда!

NEAR была основана в 2017 году Ильёй Полосухиным, одним из создателей технологии трансформеров, и Александром Скидановым как попытка создать систему, которая бы решала задачи по спортивному программированию. О том, что получилось тогда, можно почитать здесь.

В итоге NEAR сделала большой поворот на 180° и начала работу над протоколом блокчейна, который запустила в 2020 году.

В этом году NEAR сформировала новую лабораторию, NEAR.AI, задача которой — создание будущего, в котором технологии искусственного интеллекта открыты и доступны всем, а не контролируются небольшим количеством мега-корпораций.

Одним из направлений работы является обучение моделей мыслить рационально, и задачи по спортивному программированию — это отличное окружение для этой задачи. В этом контексте NEAR приглашает всех русскоязычных участников Codeforces с рейтингом 1600 и выше помочь нам описать решения задач по спортивному программированию. Мы хотим описать решения большого количества задач разной сложности и платим за это сравнительно большое количество NEAR.

Присоединиться к системе можно по этой ссылке.

Помимо этого, в раунде предусмотрены призы, не связанные с этим приглашением:

  • Ⓝ 512 за первое место,
  • Ⓝ 256 за каждое из мест 2 и 3,
  • Ⓝ 128 за каждое из мест с 4 по 7,
  • ...
  • Ⓝ 1 за каждое из мест 512-1023.
  • Проголосовать: нравится
  • +729
  • Проголосовать: не нравится

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

good luck children

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

When you realize majority of the testers are in blue to orange range. Barely any anywhere else. Will that impact anything?

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

Excited to participate!

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

Please don't be like 74TrAkToR

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

happy new year!

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

why was good bye 2023 rated?

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

where's score distribution?

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

As a parent, I can confirm that _istil is cute!

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

and 251Sec for being invited to test but have no time to do virtual. :(

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

Congratulates!!!!!

No 74TrAkToR 74TrAkToR for Goodbye again!!!!!!!!

»
22 месяца назад, скрыть # |
← Rev. 4  
Проголосовать: нравится +148 Проголосовать: не нравится

As not a tester, I didn't test.

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

As a tester, Happy New Year, and I hope you can achieve a positive delta in this contest as a New Year gift. :)

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

I like _istil's round.

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

As a tester, _istil is cute

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

As a not-tested tester, I didn't test because of my chemistry homework (actually, my chinese homework helps as well). Anyway, wish you guys positive delta!

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

As a tester, the problems and the problemsetters are cute and wish you all have fun in this contest!

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

As a kicked test,I want to cry!

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +31 Проголосовать: не нравится

As a tester for the first time, what can I say.

The other testers are very good at expressing, but I can only say that this contest is the best one of the year.

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

Rated?

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

As a tester, I went cyan, which is the same color as _istil's, to express my adoration for _istil.

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

Hope it doesn't end up like good bye 2023

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

As the only "LGM" "writer" of this "specialist round" (though I proposed no problems actually), I wish you good luck, positive delta and a happy new year! (I believe an lgm may make the round look better :)

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

chill guys , This is another masterpiece coordinated round by TheScrasse , (orz).

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

Happy New Year! and well wishes for the positive delta for upcoming year.

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

2024 is meaningful to me.It is a perfect way to end this year to take part in the expecting contest!

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

As a tester, the problems are worthy of being in Good Bye round. Do not skip this one!

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

Is this rated?

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

is this rated??

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

my last chance to get expert this year. I hope I can do it and not bottle it again 😭😭😭

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +62 Проголосовать: не нравится

8-12-2024

alzahrawi

Alnafis

alkhwarizmii

-Ananas-

albirunii

Zanaty_8

-Oak-

-DragonFruit-

-Orange-

-Blueberry-

As FruitSalad community, we look forward for participating in this contest ^^

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

and 251Sec for being invited to test but have no time to do virtual.

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

As a tester, _istil is cute and problems are more interesting than Goodbye 2023. GL&HF!

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

Let's Go

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

As a tester,I've lost a chance to gain rating in the end of 2024.

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

Bye Bye 2024

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

will it be rated?

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

i hope for a very good contest before 2025.

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

Hope that the round can be much better than Goodbye 2023

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

Is this round rated or unrated? Also, will it be like educational rounds or normal (div1+ div2) rounds?

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

I hope I no longer need to use magic to change color :)

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

Happy new year! Hope to gain more rating in the last contest of 2024, good luck and have fun!

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

is this rated??

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

hope the contest can be great

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

Is it rated?If so,the rated range?

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

Is there not going to be a Hello 2025 this year? So far it isn't in the contest list..

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

I hope Good bye 2024 will not be the same as Good bye 2023

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

That ishaandas1 for green testing is more like specialist or expert , visit his profile his ranks are under 3000 and if on this basis if ranks were calculated than our rating can be deducted

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

what do you mean by featured prizes ?? is this something related to ratings

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

Who can tell me the score of each question

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +43 Проголосовать: не нравится

$$$2025=45^2$$$ probably the only perfect square number year throughout my lifetime...

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

Is it ICPC format (Penalty , etc) or Points format (Points per problem ) :D ??

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

i can predict that 2024 will be in either question or constraint

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

I hope to become blue in this round!!

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

As a tester I can finally write a hint for you guys.

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

Time to be a pupil before the end of the year haha

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

As 2024 is coming to a close, I would like to wish everyone a Happy New Year in advance and good results in the upcoming competitions. I am very passionate about algorithm programming.

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

I hope this contest is unlike the last two T-T.

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

I Wish every person in the Competitive Programming Community Belated Merry Christmas & Happy New Year in advance...

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

What is Ⓝ? I search Bing but not results.

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

rare round dont have thanks for "MikeMirzayanov for the Codeforces platform" O.O

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

I don't get why couldn't the author just mention if the round is gonna be rated or not

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

score distribution?

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

Score distribution??

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

score distribution when ?

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

What is Ⓝ ? Can someone explain please

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

Wont participate because i feel like its going to be mathforces cuz of chinese setters.

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

As some testers' friends, I didn't test.

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

What is N in this, I mean in the prizes??

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

(insert Good Bye 2023 trauma joke here)

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

Just a selfish question.

It is 6 questions to hit Expert.

5 questions to remain cyan and climb a bit

4 questions to de-rank to pupil

3 questions to de-rank to pupil

=2 questions to de-rank to newbie

Am I correct?

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

Hopefully I can gain some of the 100 ELO I lost after getting hacked last round.

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

2025=45*45 probably the only perfect square number year throughout my lifetime

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

How can NEAR be received? Can top 1023 participators receive their prizes by.. TON wallet or anything other? I haven't found any wallet about NEAR in WALLET yet.

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

Is this round rated?

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

Participating after 7 months,wish me good luck

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

Time will pass, and we might meet again. Looking back at the past, everybody has lived the life they wanted. From NOI2024Day2T1

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +27 Проголосовать: не нравится

Pretests passed, 32 ms under time limit:

And 16 ms under TL for systests.

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

Solved D and E in 30 minutes,spent 2 hrs on C and still no idea,i hate my brain.

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

How to solve C?

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

    A naive approach would be to do simple recursion:

    long long predictLuckVal(long long l, long long r, long long k) {
        if (r-l+1 < k) return 0;
        if (l == r) return l;
        long long m = (l+r)/2;
        if ((r-l+1)&1) return m+predictLuckVal(l, m-1, k) + predictLuckVal(m+1, r, k);
        return predictLuckVal(l, m, k) + predictLuckVal(m+1, r, k);
    }
    

    This gives the correct result but is very slow. We need to optimise it.

    Notice that each time we split the current interval [l,r] in 2 intervals with equal lengths, the operations done on the 2 intervals will be exactly the same in terms of splitting. The only difference between the 2 intervals we are doing recursion on is the values that we are adding.

    Let's say we are recursing on two intervals of equal length (after a split). Call them L and R respectively.

    First observation: the number of stars that will count to our luck score from L should be exactly the same as that coming from R (why? because both intervals have same lengths).

    Second observation: for each star that is counted in from L, there is a star counted from R such that m (or m+1/2) is their midpoint. Call the star that we collect from L m1, and the one collected from R m2, then (m1+m2)/2 = m. To be precise, if the split came from an interval with odd length, the relation would be (m1+m2)/2=m, else it will be (m1+m2+1)/2 = m.

    So do we really care what the value of m1 and m2 are? No. Because at the end we collect both, so we should add m1+m2 to our luck score. This is as simple as 2m (or 2m-1).

    The solution reduces to only knowing the number of stars that we should consider in only one of the intervals obtained after the split.

    The solution will be as follows: If the current interval has odd length, the answer is m + 2mX. If the parent interval has even length, the answer is (2m-1)*X.

    Where X is the number of stars that count into our luck in only the left interval obtained after the split.

    This gives a complexity of O(logN)

    You can check my code for the implementation.

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

    We need to add the yellow numbers here, notice how 6->17 has a distance of 11 (where its subarray split), 3->9 and 14->20 have a distance of 6 (where their subarrays split) and 3->14 and 9->20 have a distance of 11 (where the subarray before them split)

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

D explanation, please

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

    use greedy answer is always multiply elements of a, b in sorted order.

    then answer only change if a[x] == b[x] on the sorted order I mean, so update answer on those incidents

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

    First, the optimal strategy is to always re-arrange b so that the relative sort order is identical to that of a.

    In other words, the maximum item of b should be at the same position as the maximum item in a.

    This will guarantee the defined product P to be maximised.

    Rearranging b initially to fit into this condition can be done using sorting (sort both arrays while keeping track of each item's initial index).

    After doing this, calculate the initial value of P.

    After that, each time an operation happens, we need to rearrange b to fit the condition. The trick is that we don't need to do sorting again. It will be sufficient to swap at most 2 items to get the new optimal arrangement.

    To make things easier, let's first sort both arrays, keep track of the initial index of each item in map (or array), call this index_mapper_a, and index_mapper_b respectively.

    In other words index_mapper_a[i] = the index of the ith item of a in the sorted version of a (same for index_mapper_b).

    To give a concrete example: suppose a = [1,5,3,2], then a_sorted=[1,2,3,5] and index_mapper_a = [0,3,2,1]

    index_mapper_a[1] = 3 because a[1] is placed at index 3 in the sorted array.

    Now if we receive a query to increment the ith item in a. We first need to retrieve the position of this item in the sorted array. We can do this using index_mapper_a. Let's denote x = index_mapper_a[i]. We need to increment a_sorted[x]. This might ruin the sort order. We need to fix the position of the incremented item in the sorted array.

    If x == len(a)-1 or a_sorted[x] <= a_sorted[x+1], then a_sorted[x] is still in the right place (i.e. the sorting is preserved).

    Else, we need to find the new position for it. We know that a_sorted[x+1:len(a)] is already sorted. So we can simply do binary search to find the new position of the incremented item. We should binary search for the first item Y in a_sorted[x+1:len(a)] such that Y >= a_sorted[x] (after incrementation for sure), we should then place a_sorted[x] just before that item. We can do this simply with a swap.

    Example, if we had [1, 2, 2, 3, 3, 3, 5]. Let's say we had to increment the fourth item. We will get [1, 2, 2, 4, 3, 3, 5]. We binary search on [3, 3, 5] for the first Y such that Y>=4. We get 5. So 4 should we swapped with the item just before 5. So we get a sorted array again: [1, 2, 2, 3, 3, 4, 5].

    When doing these operations, you should pay attention to update the index_mapper_a.

    Finally, when we obtain all these information, we can update the value of P very simply:

    We need to remove some factor from P and add some factor to it based on which item we swapped a_sorted[x] with.

    Some final notes: - The case where no swap is needed should be handled so that we don't remove/add a factor that shouldn't have been added/removed. - Adding a factor is done by multiplying the new factor with P. - Removing a factor is done by dividing P by it. - As we need the answer modulo m, we need to also apply inverse modulo using fermat's theorem and modular exponentation.

    Check my implementation for more details.

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

Hmm interesting problems but understand statements was very challenging for me specially problem E

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

perform really badly but quality contest imo. probably one of best in 2024

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

E seems significantly easier than D , especially in a contest ..

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

choked on C for 1hr 20 min and solved D within 25 mins :)

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится -25 Проголосовать: не нравится

So why can't my code for problem E pass the last test case of the samples? The answer should be 171, but my code output 170.

// #pragma GCC target("avx")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define eb emplace_back
#define int long long
using namespace std;
const int N = 500100;
vector<int> adj[N];
int deg[N], f[N], up[N], siz[N];
void dfs(int u, int fa) {
    up[u] = fa;
    siz[u] = 0;
    if (deg[u] == 1) {
        // f[u] = 0;
        return;
    }
    for (auto &v : adj[u])
        if (v != fa) {
            dfs(v, u);
            if (f[v] > 1) siz[u] += siz[v] + 1;
        }
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            deg[i] = 0;
            adj[i].clear();
            up[i] = -1;
            siz[i] = 0;
            f[i] = 2;
            siz[i] = 0;
        }
        for (int i = 1; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            adj[x].eb(y);
            adj[y].eb(x);
            ++deg[x], ++deg[y];
        }
        if (n == 2) cout << "0\n";
        else {
            int root = 1;
            while (1) {
                if (deg[root] > 1) break;
                ++root;
            }
            for (int i = 1; i <= n; ++i)
                if (deg[i] == 1) f[i] = 0;
                else {
                    f[i] = 2;
                    for (auto &j : adj[i])
                        if (deg[j] == 1) f[i] = 1;
                }
            dfs(root, -1);
            // int ans = 0;
            // for (int i = 1; i <= n; ++i)
            //     if (f[i])
            //         for (int j = 1; j <= n; ++j)
            //             if (j != i) {
            //                 if (!f[j]) ++ans;
            //                 else {
            //                     if (f[i] > 1 && up[j] != -1 && f[up[j]] == 1)
            //                         ++ans;
            //                 }
            //             }
            // for (int i = 1; i <= n; ++i) if (up[i] != -1 && f[up[i]] == 1 && f[i] > 1)ans -= siz[i];
            // cout << ans << '\n';
            int c0 = count(f + 1, f + n + 1, 0ll);
            int c1 = count(f + 1, f + n + 1, 1ll);
            int ans = 0;
            ans += c0 * (n - c0);
            // ans += c1 * (n - c0 - c1);
            // ans += c1 * (c1 - 1);
            int gg = 0, mm = 0;
            for (int i = 1; i <= n; ++i)
                if (up[i] != -1 && f[up[i]] == 1 && f[i] >= 1) ++gg;
            for (int i = 1; i <= n; ++i)
                if (up[i] != -1 && f[up[i]] == 1 && f[i] > 1) ++mm;
            ans += (gg) * (n - c0 - c1);
            ans -= mm;
            cout << ans << '\n';
        }
    }
    return 0;
}

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

F killed segment tree successfully!

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

omg jiangly accepted G and rose up to the first position in the last minutes

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

How did problem E get by the readers/testers, being so badly written?

The problem never says that (the definitions of) p and q are updated, which is rather important...

Also, the definition of dominated is really unnecessary; one can just define the caterpillar as the path and then talk about vertices in the path (or not in the path).

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

I thought my solution to I2 is wrong so I only submitted at the end due to desperation...

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

Is I1 ChatGPT-able?

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

This contest has made me think my life choices....

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

A<B<D<E<C

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

    D seemed way more painful than C to me. For C you just need to abuse the fact that each tree of the same size is identical. The only difference is you need to add a constant to the tree if the base is not 0.

    For instance if you have (base 0 -> [1, 2, 3]) and (base 3 -> [4, 5, 6]), you don't need to compute the [4, 5, 6] branch of the tree, just take the computation of the base tree and add some constant 'C' * amount of nodes taken from the smaller tree

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

Man I wasted way too much time on C, couldn't implement D quickly enough afterwards

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

Finally, I think my performance on this contest was actually representative of my skill (maybe enough to finally reach expert).

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

    Congrats on reaching expert! What was the approach for E?

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

      Thanks :))

      E solution: precompute for each node toleaf[i], denoting the shortest distance from i to any leaf (using dfs pretty simply). Then, the idea is that, if toleaf[p] < 2, A wins always. So, we just consider toleaf[p] >= 2. We can consider the cases where q is a leaf and when it is not. When q is a leaf, we have n-leaves other nodes to be p, so the answer is already set initially to (n-leaves)*leaves. Then, we consider the second case, where q is non-leaf and toleaf[p] >= 2. In this case, we iterate over each node in the tree, consider it as being q, then for each adjacent node v, consider cnt[v] (which we also will have computed before) to be the number of nodes in v's subtree that are "good" (i.e. toleaf value >= 2). "good" vertices are ones that p can be assigned to. Using this info, we can compute the number of corresponding p values for the given current q.

      UPD: I should have added the key fact: if toleaf[v] >= 2, then q being "dragged" in that direction by p will result in a tie, with A and B just reversing each other's moves.

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

quite bit surprised on the fact that A, C was not GPT solvable, which is very uncommon in recent contests. problemsetters must put a lot of effort into this.

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

aaaaaaaaaaa I misread problem D thinking it was increase ai/bi by x and thus harder than it really was. I didn't realise it was only increase by one until too lateee

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

ABC felt a bit too difficult, even though I enjoyed them. E is alright — maybe a bit more enjoyable if we solve for first player, but then it'd be too easy. Gap E-F is hard, but maybe it's my skill issue :). Overall felt kind of balanced.

What I can't understand is the intended solution for D: whatever you do, you need to keep track of the two sorted sets, and be able to recover an element by index and vice versa. This is either a lot of pain to implement, or a no-brainer pbds. For div1 that's alright either way (I did a pbds), but I feel sorry for less experienced participants: if you don't know pbds, you'll likely have a really hard time debugging the implementation yourself, even though the greedy idea is a good one for this position.

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

    you need to keep track of the two sorted sets, and be able to recover an element by index and vice versa.

    No, because the operations are only $$$+1$$$, you can just add to the last occurrence of $$$A_x$$$ instead of whatever random occurrence you got. This solves the problem in a much cleaner way, and without any heavy structures. You can take a look at mine/jiangly's implementations

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

      Oh, that's smart, we basically never swap elements. Then there exists a clean solution, you are right! Still not sure if it is easily identifiable on the spot — i havent thought enough during the contest because pbds was not that difficult to include.

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

        I feel like your solution doesn't work with arbitrary changes of elements. Let's say, you have a = [1, 2, 3] and b = [1, 2, 3], and then you change a[0] from 1 to 4. Then the answer changes significantly, because 2 and 3 from a shift to lower positions. Therefore, your solution also implicitly uses the fact that the operations are just +1, and the array doesn't change a lot.

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

          It probably doesn't, I indeed do use the fact we have the groups of same values. It is just the next (not obvious for me) step — that the array transforms without swapping elements.

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

    My code for D isnt that hard

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

How to do B? Thought of an algo but it became too complicated to implement

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

    If l==r this means you do not have any choice but to fill that index with L

    If l!=r you have r-l+1 choices It is mentioned in the problem that the max value of ai can be upto 2*n

    So maintain an array (arr) of size 2*n

    if l==r set arr[l]=1

    and maintain an frequency array which stores frequency of all l's such that l==r

    Now create a prefix sum array which stores the prefix sum of the arr.

    Prefix sum array is used here to find how many indices l are present which have l==r

    now coming to algo if l==r and frequency of l>1 print 0 if l==1 print 1

    if l!=r count prefix[r]-prefix[l-1]. If that value is less than r-l+1 print 1 else print 0

    that's it!

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

Did C in log^3(N) by drawing trees and observing a pattern. Ended up being more difficult than intended.

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

I feel dumb, but these are great questions. Much to learn.

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

Why is the second player in E named Aron?) Kind of confusing (at least for me)

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

I failed to pass G because the stack limit of the problem is too small, like much smaller than the memory limit. Shouldn't the stack size be the same as the memory limit?

link. After comparing my solution with some other accepted ones I'm really sure that it should have been right.

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

    As far as I remember, it should be the same as memory limit — but maybe it was just increased to 256 MB or so.

    You have a lot of memory in the global arrays, but those should be statically allocated on data segment and not on stack, though maybe Windows calculates stack overflow differently because it's a stupid OS.

    Have you checked how much call stack can grow? Make a test with maximum DFS depth, perhaps check assembly to see how much gets pushed at every call, or measure how much you need to set stack limit so it'd narrowly pass.

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

      Stack size in codeforces is 256 MB (and in problems with lower memory limit, you will sooner get MLE than runtime error from stack overflow). So that answers why you got Runtime Error.

      As to why Codeforces does this, no idea, but it has been like this for a long time.

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

        MLE is most likely an OS check. Dynamic (heap) allocation strategies are weird and OS-dependent (like memory overcommit on Linux) and can be configured; automatic (stack) allocation not so much, but I suppose it can involve an OS check too.

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

Am I the only one who struggled with B for an hour? Is there a way to solve it without Fenwick/segment tree?

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

Screencast of me writing this round in rust will eventually be available here

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +164 Проголосовать: не нравится

After a rather long hiatus, I participated again in a contest. Here is some feedback on the problems:

  • A: The statement is not very interesting (and unnecessarily long).
  • B: This one is a div2B datastructure problem. It is rare to have an easy problem that involves some thoughts about datastructures and this one seems appropriate.
  • C: A cute problem that I liked. It has a project-eulerish flavour.
  • D: Ok, another easy datastructure problem. I don't see the point of this one. I knew how to solve it as soon as I finished reading it, then I pushed through the pain and implemented it (and I made a mess...). Arbitrarily adding queries to a problem to increase its difficulty should be forbidden as it creates monsters.
  • E: The problem is not very interesting. I read the statement twice as it seemed so much more complicated than the solution that I thought I had misread it. This problem looks superficially very interesting but after 1 minute of thinking it is rather clear that there is no hidden structure to discover.
  • F: To solve this one I had to think for some time and I liked having a break from coding. Of course, the hard part was implementing the solution. For some mysterious reason, I enjoyed also implementing it. My solution needed a data-structure representing an enhanced array that could support: get value, get max, max one value with, max all values with, add x to all values. It was abundantly clear to me that this was doable, but not clear how. I am rather happy with the thing I implemented, which supports all operations in O(1).
  • G: Skipped.
  • H: Skipped.
  • I1: The standings suggested that I should give a try to this one. I read the statement and it did not seem particularly interesting. After thinking for a few minutes I guessed (without proof) that the greedy algorithm might work. Maybe I could have proven it, but I decided to just have some faith (possibly because the contest was close to its end...). I implemented the greedy idea in a horrible way and magically got accepted.

Overall, the contest felt average—not particularly enjoyable, but not unpleasant either. I enjoyed solving and implementing Problem F, and I think that problem B and C could be nice for contestants less experienced than me. I hated the unnecessarily long statements involving ridiculous stories about pretty weird presents as well as all the headers before the actual statements with links to stuff in Chinese (I would be very supportive of codeforces if it were to decide to ban any kind of stuff in the statements of rated contests that has nothing to do with the problem and is longer than one line).

Thanks to the authors and to all those involved in the organization of the contest.

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

    I also thought problem D was annoying, than I realised that you don't actually need to keep track of the indices.

    Simply keep the original array, and process the queries one by one (applying them to the original arrays). When a 3 is updated to a 4 it doesn't matter which 3 was updated in the sorted version, so you just find the last 3 and increment it by one.

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

    Has there been a vote or proposal ever to rid of the fluff before the actual problem statement? I'm curious how many people would support fully abolishing all of it.

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

D fails when using std::map and std::set and cleverly swaping elements with overall time complexity of O(Q log N), but apparently passes easily when using GNU's Tree structure with very similar constant factors. Come on, test better next time. Absolute bs.

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

Goodbye Master QQ

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

Implementation of D using only std::vector: 298847993 We only need to update the last element with the value a[x] or b[x], not the exact element at index x

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

Nice problems!

DE were especially sweet, very neat and not implementation heavy. Sadly, I couldn't finish E in time as I spent too much time on CD.

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

Any hints for F? Please

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

I feel I1 is overscored than its difficulty. Normally, the subtask score is given so that it is slightly lower than its difficulty, so I guessed the difficulty of I1 is about 3500pts problem in this contest, but actually F>I1 for me.

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

Every time I participated goodbye round, my rating is also "goodbyed".

»
22 месяца назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +79 Проголосовать: не нравится

Thanks for the round!

My screencast with mumbling and a 8-minute post-contest recap at the end.

Two points from the video:

  • I finished I2 in 5-10 more minutes after the end of the round, and it passed systests, and it would be enough for the second place :(
  • The way I solved G, and the way I was planning to solve H if I had more time (and how Egor solved H) is to use a stress-test to verify and/or improve reasonably motivated but unproven simple approaches. Which is notoriously close to how LLMs seem to be solving problems :)
  • »
    »
    22 месяца назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    And of course I have solved the same wrong version of I2 as the contest authors, where we count not just arrays b, but also the ways to choose a out of b.

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

    the way I was planning to solve H if I had more time (and how Egor solved H) is to use a stress-test to verify and/or improve reasonably motivated but unproven simple approaches.

    I'm curious, is there some way to solve H without stress testing when you get WA? I don't see how anyone could deal with all the $$$a_i=w$$$ cases correctly on the first try.

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

Liked the problems but not the statements. Specially the statements of problem A, B and E were unnecessarily complex.

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

Problem C.

  1. Let's solve only for odd sized array.
  2. Say N=11, then 6 is selected.
  3. Some elements from the range [1..5] and some from [7..11] will also get selected.
  4. By symmetry, if 2 is selected then 8 will also be selected.(2nd element from the left half and 2nd element from the right half).
  5. This means the average of the element selected from left and right halves will be = 6 or (N+1)/2.
  6. So problem reduces to finding how many total elements(other than the middle element) will be selected.
  7. By symmetry, equal elements will be selected from both halves. So we need to only find count of elements that will be selected from a segment of size (N-1)/2.
  8. Final answer = middleElementValue + middleElementValue*(countOfElementsSelectedFromRightHalf)*2.

countOfElementsSelectedFromRightHalf can be calculated using recursion in logN time.

Similar reasoning can be used to find answer if N is even.

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

https://codeforces.me/blog/entry/137621?#comment-1233118 Is this means that intended solution for I2 is broken? If so, how do we treat about this is it wholey unrated?

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

    Yes, it is broken. It's being discussed here. Personally, I don't think making the contest unrated is a good way to solve this: there are prizes involved, not giving them to anyone would be wrong (especially when the amount of people receiving prizes is much bigger than the amount of people affected by this), so that has to be dealt with, and giving the prizes while also making the contest unrated doesn't really make sense to me.

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

C was very new to me, E was a very nice problem if I was not stuck on problem C, I could've solved E.

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

Can someone clarify why my submission to problem B 298887302 was accepted in Java 8 32-bit, but the same solution with submission ID 298901051 is giving a TLE in Java 21 64-bit?

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

Some cf rounds really tell me how mathematically challenged i really am. I was able to solve A,B,D but my mind died solving C. I have respect for everyone who was able to solve C by themselves.

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

Yes I'm that Aquawave in problem F as the leader of RiOI team XD

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

Can someone explain me problem B? The input and output do not make sense to me. Also the question itself. Thanks

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

    basically you have print 1 if you can give ith query a unique value like between (Li and Ri) while making sure other values in array can be anything but not equal to the value you giving to current i. basically if you are assinging 'X' to current (ith query) , you have to check it will be unique like (other query can be assigned some diffrent value). Only values that can cause concern is when Lj==Rj. I dont know if u understood. you can use line sweep or ordered set to implement it

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

Problem B:

//code for Problem B 
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const ll MOD = 1e9 + 7;

void solve(){
    ll n;
    cin >> n;
    ll left[n];
    ll right[n];
    ll arr[400001];
    map <ll,ll> m;
    for(ll i=0; i<400001; i++){
        arr[i] = 0;
    }
    for(ll i=0; i<n; i++){
        cin >> left[i] >> right[i];
        if(left[i] == right[i]){
            m[left[i]] += 1;
            arr[left[i]] = 1;
        }
    }
    
    ll prefix[400001];
    prefix[0] = 0;
    for(ll i=1; i<400001; i++){
        if(arr[i] == 0){
            prefix[i] = prefix[i-1]+1;
        }
        else{
            prefix[i] = prefix[i-1];
        }
    }
    for(ll i=0; i<n; i++){
        if(left[i] == right[i]){
            if(m[left[i]] > 1){
                cout << 0;
            }
            else{
                cout << 1;
            }
        }
        else{
            ll free = prefix[right[i]] - prefix[left[i]-1];
            if(free > 0){
                cout << 1;
            }
            else{
                cout << 0;
            }
        }
    }
    cout << endl;
    return;
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll tt;
    cin >> tt;
    while(tt--){
        solve();
    }
}

Can someone tell me WHY this was TLE'ing, I couldn't figure it out for the life of it and had probably my worst contest ever.

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

Why did GroupMatrix's rating drop, while the performance is 3114 (way higher than the previous rating)? MikeMirzayanov

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

Anyone who had a bad performance will send that he was affected by I2, and thus, all the people who had negative rating change will be unofficial which will affect the rating of other people, for example, being the 300th on 20000 participants is better than being 300th on only 5000.

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

    Surely this is false; there has to be some level of reasonability to these requests, for example a newbie with no past experience of even solving or attempting to solve D's or E's is highly unlikely to be affected by I2. In fact, it's very likely if you haven't solved everything until F that would would be affected by I2 because why would you be attempting I2 in the first place?

    edit: technically it is true, but the extremeity of the jump shouldn't be (it would probably go from 20000->19000 at worst realistically)

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

Did the Near prizes get sent out?

How will I know when I got it (system notif)?

How much time does it generally take

Also if anyone is in India can they tell the easiest way to cash it

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

Hello. My submission for problem D got skipped for being too similar to another one. I didn't cheat. 1/3 of my code is a template, 1/3 is fast exponentiation (both of those I can find in my past submissions for sure) and the rest is a primitive solution. The other submission's author studied in the same school as I did, but I don't know him personally and never spoke to him ever. TheScrasse