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

Автор induk_v_tsiane, история, 3 года назад, По-русски

Hello, Codeforces.

We are happy to invite you to Codeforces Round 892 (Div. 2), which will take place on 12.08.2023 17:35 (Московское время). All of the problems are original and were prepared by a collective of authors, consisting of kristevalex, artew, efimovpaul and me, induk_v_tsiane. This round will be rated for participants with a rating lower than 2100.

We would like to thank:

You will be given 6 problems and 2 hours to solve them. The score distribution is 500 — 1000 — 1250 — 1750 — 2250 — 3000.

I would like to also congratulate my cousin Max, who is turning 30 the day of the round. If you wish, you can write birthday wishes for him and I will pass them on.

UPD: Editorial

UPD 2: Congratulations to the winners!

Div. 2:

  1. modulo998244353

  2. botjiaxun

  3. Tmath_OneLove

  4. FengjianZhu

  5. Alihan_8

Div. 1:

  1. Geothermal

  2. heno239

  3. maspy

  4. jiangly

  5. Ormlis

  • Проголосовать: нравится
  • +776
  • Проголосовать: не нравится

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

As a participant I hope to get 1300+ rating or even better, Specialist

Also Happy Birthday Max, sending you best wishes

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

As a tester I recommend you to take part in this beautiful round

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

кшк база

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

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

As a tester, I can say that the tasks are cool and interesting

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

As a "кошка база" I recommend you to participate in this round!

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

As a tester, I wish Max all the best on his birthday! Also, round is going to be fun, trust me ;)

p.s. имя нам улей

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

Кошка база٩(๑❛ᴗ❛๑)۶

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

С днем рождкния, Макс!

кшк бз

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

Is this rated? Please dont downvote. Tomorrow is my birthday.

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

As a tester good luck! You will need it

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

As not a tester good luck!

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

As "еритв" I also recommend you to participate in this round!

P.S. Имя нам улей

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

happy birthday Max

may i reach my Max rating in this contest

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

Happy birthday to bro Max

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

As a tester I recommend you to take part in this round!

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

Can I hope ......

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

Кошка база №1

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

as a tester, I can say that the round is interesting, I recommend participating

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

as an author, i recommend you this round!!

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

Feliz Cumpleanos Max!!! I express my deepest regrets for not being able to participate in the round for I am participating in the Teamscode competition which unfortunately has overlap w/ this round. :/ GL to everyone!!!

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

as someone who just saw this announcement, it might going to be a good round. GL on the round guys!

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

What is meant by “All of the problems are original” ?

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

Happy birthday to Max!

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

dori dori dori dori

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

As a tester, this round isn't very good and I recommend you not to participate.

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

As a tester, this round is mid and I don't recommend to participate.

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

Автокомментарий: текст был обновлен пользователем induk_v_tsiane (предыдущая версия, новая версия, сравнить).

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

С днюхой Макс, надеюсь раунд подготовленный твоим двоюродным братом будет очень интересный!

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

As A participant I wish to reach Expert hopefully, and Happy 30th Birthday to Max <3

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

Happy Birthday Max!! Best wishes!

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

Happy birthday to Max!

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

how to have huge postive delta:)

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

A very Happy Birthday to Max.

I hope he gets Max happiness and we all get Max positive delta so that we can have Max smile on our faces after the contest and practice at our Max level to surpass our Max rating.

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

As a tester I recommend you to take part in this round!

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

As a participant I hope to get 1200+ rating or even better, Pupil

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

Thanks for this round and good luck to everyone!

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

as a normal person, please downvote me

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

Happy Birthda ,Max!

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

Happy B-day Max

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

As a participant, hoping to be pupil this time. Also Happy birthday Max best wishes from my side too.

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

My rating decreases in div2 :(

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

As a participant, I hope to get a rating of 1200+ to become a pupil. Guys, please suggest ways to improve my logic-building skills.

Happy Birthday, MAX, wish you all the best in your future endeavors.

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

As a regular participant I hope I reach 1200+ rating...

Thanks for the round.. Looking forward to it.

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

As a participant, I hope to become pupil.

Also Happy Birthday Max.

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

Max is lucky to have a cousin like induk_v_tsiane. Happy Birthday, Max, Best wishes to you.

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

As a tester, I recommend everyone to participate in this round. The tasks are interesting. I wish you all good luck and positive delta.

Happy birthday, Max!

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

Happy birthday Max !

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

The score distribution is very nice and hope that the tasks are cool and interesting.

Also Happy Birthday Max, sending you best wishes <3

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

Hi

I have zero experience

How can I participate in the event? Can someone help me!?

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

    Just register for it. Keepthe score distribution in mind if you are not used to competitive programming -- first task should require just an idea, and last ones will test your understanding of data structures.

    You can download carrot or cf-predictor chrome extension to see your predicted rating based on ongoing contest performance

    I solved 0 problems in my first contest, btw)

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

☠️☠️☠️

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

Happy BirthDay Max !.Wish you the best.

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

Happy Birthday MAX. Hope i will reach my MAX rating by participating in this contest.

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

Happy Birthday MAX. I wish you the best. And wish me that i can reach my MAX rating by participating in this contest.

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

Happy birthday to MAX!

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

I'm hoping for a big negative delta to celebrate my birthday too(((

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

Happy Birthday, Max. Best wishes to you.

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

Hope my fever goes down so i can participate.

Also,best wishes to Max.Have a great day.

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

Hope u guys have a good "fate" round.

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

buru nyuu

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

Happy Birthday Max,sending you best wishes

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

I hope to get Candidate Master rank before the first day of my 3rd semester which will start 2 days after this round :)

And also.... happy birthday max ^_^

UPDATE: I failed :(

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

All the best to all my friends.....

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

Hope to solve 3 question in this contest.

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

Hope, this day, Max, will help everybody to reach their MAX rating)

wish u good luck and happy 30th birthday!!

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

Happy Birthday, Max c:

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

Happy Birthday Max:)

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

good luck & have fun

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

Happy Birthaday Max, Sending you best best best wishes

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

Looking forward for the contest desparately...

Also, Happy Birthday Max Tell him we sent virtual hugs :)

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

Happy birthday Max!

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

C днем рождения, Макс!

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

Lets Goo. My first coding contest ever. So anxious and excited at the same time

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

Dear Max, Warmest congratulations on your birthday! I hope this special day brings you immense joy, wonderful memories, and a year filled with success and happiness. Wishing you all the happiness your heart can hold. Warmest regards, Faizullakh, Dilettante_786

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

Арт прикольный

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

Happy birthdayneco arcneco arcneco arc

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

Who is Max?

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

As a participant I just hope to get rated and nothing else

Also Happy Birthday Max, sending you best wishes

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

can anyone tell me, if there is any correlation between the question's score and rating? A score of 1000 means, the question is around 1000 rating difficulty level?

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

    Rating 1000 means that a person rated 1000 has a 50% chance of solving this problem DURING the contest

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

    No, there is no exact correlation. Sometimes the scores might be close to the problem ratings, other times they might be very different. Scores try to reflect the difficulty of the problems (higher score — harder problem; much higher score — much harder problem) but it's often difficult to accurately determine the difficulty of the problems based on the opinion of only a handful of people (problemsetters and testers).

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

As a participant I hope to get 1600+ rating or even better,Become first time Expert.

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

As a participant I hope to get 1800+ rating or even better, CM

Also Happy Birthday Max, sending you the best wishes

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

As a participant I hope to get 1800+ rating or even better, Candidate Master

Also Happy Birthday Max, sending you the best wishes

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

puranyaa

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

AGC Codeforces ?

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

It was a nice contest. Hoping to become Candidate Master in my next one. : )

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

Good visible tests! Really helpful. Hope pretests are good too.

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

-clear statement -nice problem that's a perfect contest , thanks to the organizers

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

How to solve C?

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

Segment tree for E?

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

Speedforces

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

It was hard D for me,but easy for others :(

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

New OEIS sequence when

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

Is it just me or was that round way harder than usual?

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

How to solve D?

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

Nice contest, hope to become expert this round!

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

Hi guys, I have a question that need your help.

Example with problem B, my idea: sort all arrays (A[n]), and the result is sum of second element each array (sum (A[i][1]), 1<=i<=n) (except the min — A[i][1] with 1<=i<=n), and the min value of all elements.

I tried to solve this problem with 3 — 4 wrong times answer. In each try, I realize something, and test the output with codeforces system, when wrong, I find some test cases, realize something (or not), and solve again. So, I cannot prove some problems I solved, like problem C. What happened with me! How can I improve my algorithm?

Also HappyBirthday Max.

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

how I solved C

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

Are there any hacks for problem F? I got Wrong Answer on Pretest 3.

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

I have no idea how to solve A, but I know how to solve F:

First, let's notice that we will take courses at most $$$logmaxW$$$ times because after that time spent on traversing a road will be equal to $$$1$$$. Also, all courses will be taken in the first possible city/node (to minimize time spent on the rest of the travel). I have precomputed with binary lifting:

$$$up[i][j] -$$$ $$$2^j$$$-th ancestor of node $$$i$$$

$$$cnt[i][j] -$$$ the number of nodes $$$u$$$ on path from node $$$i$$$ to the $$$2^j$$$-th ancestor of $$$i$$$ such that $$$s[u]=$$$ '$$$1$$$'

$$$sum[i][j][k] -$$$ time spent on traveling from node $$$i$$$ to $$$2^j$$$-th ancestor of $$$i$$$ if the skill is equal to $$$c=2^k$$$ all the time (without including the time needed to take that $$$k$$$ courses).

Let's define $$$f(u,v,k) -$$$ time spent on traveling from node $$$u$$$ to node $$$v$$$ if the skill is equal to $$$c=2^k$$$. This can be calculated in $$$O(logn)$$$ using arrays $$$up[i][j]$$$ and $$$sum[i][j][k]$$$.

For answering the query ($$$a,b$$$), we will find the necessary time to travel from $$$a$$$ to $$$b$$$ for every $$$k$$$ from $$$0$$$ to $$$logmaxW$$$, where $$$k$$$ will be equal to the number of taken courses. For each of the results, we need to find the first node $$$u$$$ on the path from $$$a$$$ to $$$b$$$ such that $$$s[u] =$$$ '$$$1$$$' and the closest node $$$v$$$ to $$$a$$$, but not on the path from $$$a$$$ to $$$b$$$, such that $$$s[v] =$$$ '$$$1$$$ and the result will be equal to $$$min(k \cdot T + f(a,u,0)+f(u,b,k),k \cdot T + f(a,b,k))$$$ Final result will be the minimum of this results. Overall time and memory complexity are equal to $$$O(nlognlogmaxW)$$$.

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

I solved C by pre-computing and saving the answers :)

Edit: I also forgot to congratulate Max, HBD Max :D

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

Уже второй (!) раз не могу в последнюю минуту отправить решение: сначала кнопка "отправить" недоступна, потом -- сам кф. Это пипец какой-то. И во время контеста кнопка тоже периодически отваливается.

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

so disappointing when u are rank 2 15 min in the contest and now ur rank 500 at the end cuz some stupid mistakes... got a little positive delta though, nice little birthday present:P

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

I mistakenly read the meaning of problem B and got stuck for a long time.

Anyway, thank you for holding this high-quality round!

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

Problem A: You can just sort the array. Find the subarray starting from the first element, ensure that all elements of the subset are equal, and just print the subset. The next part will be for array C.

Problem B: Just store the first and second minimums from all arrays. Then sort the stored values. The ans will be first[0] + second [1] + second [2]... second [3]

Problem C: Create a permutation of size n. Then use a for loop. Reverse the given sorted permutation for j = i to n. Calculate and store the maximum of all n possible answers.

I hope it is helpful.

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

218576719 For A problem , can someone please tell me why am I getting runtime error(at pretest 1), even when this code runs fine in my sublime text.

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

Can anyone help me with what's wrong with this code for problem D? My basic idea was to sort the segments and stitch them together and finally apply a binary search for each xi to see in which stitched segment it lies.

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

Problem A: You can just sort the array. Find the subarray starting from the first element, ensure that all elements of the subarray are equal, and just print the subarray. The next part will be for array C.

Problem B: Just store the first and second minimums from all arrays. Then sort the stored values. The ans will be first [0] + second [1] + second [2]...+second [n-1]

Problem C: Create a permutation of size n. Then use a for loop. Reverse the given sorted permutation for j = i to n. Calculate and store the maximum of all n possible answers.

I hope it is helpful.

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

Hello, I would like to report an issue on question 4. Basically, I ran the code on two different online C++ compilers. For the first test case, I got the correct results on those sites. However, when I run the same exact code using CodeForces, these are the results it is giving.

14 14 23 15 28 22 
14 14 14 14 22 1967396643 14 14 15 
7 8 7 
15 14 14 30 24 17 31 4 8 
32 32 32 5 8 1967396643 4 32 

I am losing my mind because I have no clue where this random large numbers are coming from in 2nd and 5th lines. Can someone either explain or if CodeForces admin thinks this is a mistake on their side, can I get the credit for the problem?

Here's my code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
using namespace std;


int main()
{
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        pii arr[n];
        for (int i = 0; i < n; i++) {
            int l,r,a,b;
            cin >> l >> r >> a >> b;
            arr[i] = make_pair(b,l);
        }
        int q;
        vector<int> original;
        vector<pii> queries;
        queries.clear();
        cin >> q;
        for (int i = 0; i < q; i++) {
            int x;
            cin >> x;
            queries.push_back(make_pair(x, i));
            original.push_back(x);
        }
        sort(queries.begin(), queries.end());

        sort(arr, arr+n);
        vector<pii> brackets;
        pii currbracket = make_pair(-1,-1);
        for (int i = 0; i < n; i++) {
            if (currbracket.first == -1) {
                currbracket = arr[i];
                continue;
            }
            pii currele = arr[i];
            if (currele.second <= currbracket.first) {
                currbracket = make_pair(max(currbracket.first, currele.first), min(currele.second,currbracket.second));
                if (i==n-1) {
                    brackets.push_back(currbracket);
                }
            } else {
                brackets.push_back(currbracket);
                currbracket = make_pair(-1,-1);
                if (i==n-1) {
                    brackets.push_back(arr[i]);
                    break;
                }
                i--;
            }
        }
        int ans[q];
        int index = 0;
        for (int i = 0; i < q; i++) {
            int currquery = queries[i].first;
            while(index < n && currquery > brackets[index].first) {
                index++;
                continue;
            }
            if (index >= n) {
                ans[queries[i].second] = original[queries[i].second];
            } else {
                if (currquery < brackets[index].second) {
                    ans[queries[i].second] = queries[i].first;
                } else {
                    ans[queries[i].second] = brackets[index].first;
                }
            }
        }
    
        for (int i = 0; i < q; i++) {
            cout << ans[i] << " ";
        }
        cout << "\n";
        
    }
    return 0;
}
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +2 Проголосовать: не нравится
    int n;
    cin >> n;
    pii arr[n];
    

    This is a prime example of a VLA, which is known to be unreliable (and isn't even provided by standards), so it's a likely source of problems. Use std::vector or a large global array instead.

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

      The failure had nothing to do with VLA's though (see my reply to the parent comment for details).

      Also, I wouldn't say that VLA's are “unreliable”. It is true that they are not part of the C++ standard, but they are supported by most compilers, including GCC which is used by CodeForces. Compilers that don't support them will give a clear compiler error instead of doing something unpredictable.

      The main risk to be aware of is that VLA's are allocated on the stack instead of the heap. That's both their advantage and disadvantage. The advantage is that allocation is cheap compared to heap allocation with std::vector<>, especially for small vectors. The disadvantage is that you can overflow the stack when the array is bigger than remaining stack space. Fortunately, CodeForces uses a 256 MB stack size, so you can put a lot of data on the stack before this becomes a problem. For example, the arr array in this problem takes less than 2 megabytes.

      I would agree that in most cases using a std::vector<> is better, especially when the size of the array is likely to be large. In that case, the overhead of heap allocation is negligible.

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

        Fair, I've just had several occasions where VLAs did seem to turn out to be the issue (well, at least replacing them would seemingly fix the problem), so I often can't help but point it out whenever I see people using them. In addition, the underlying stack manipulation (especially when used inside a loop and with several VLAs in the same frame) still seems hacky to me. However, I've also avoided e.g. std::array for a while because of a few problems some time ago, so I'm probably not the most up-to-date on what's currently broken and what is not.

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

    The problem is that brackets.size() can be less than n, so in the bottom part of your solution you should replace n with brackets.size(), or you will access the brackets vector out of bounds, which gives unpredictable results.

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

Thanks for this great round, Also Happy Birthday Max

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

how to solve E?

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

is there a way to prove and solve C without resorting to brute force with next_permutation and print? What happen if a certain language doesn't have next_permutation like C++?

If it's not easy to prove and much easier to observe by brute force then it's total BS

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

    I took a O(n^3log(n)) approach which passed pretests in 2745ms. Out of fear of FST I then tried optimizing it without any success before deciding, "What the hell, let's just precompute all the answers".

    The approach I used was to fix i and j such that p_i=j and i*j would be the maximum value of p_i * i. Then try to place the values in descending order.

    Edit: it turns out my approach was actually the intended one (although I didn't manage to optimize the log factor. Maybe I was just paranoid). I suppose this shows how most people would go for a proof by AC instead of taking an approach that is much easier to verify but slower.

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

    I'm also not a fan of problems that are of the form “brute-force some cases, spot the pattern, guess that it generalizes, and then code up the pattern”. I actually solved problem D before C because of that reason: at least problem C you could reason about.

    But I don't think brute forcing permutations requires C++. Even in Python you can do it easily:

    from itertools import permutations
    
    def Evaluate(perm):
      terms = [i*v for i,v in enumerate(perm, 1)]
      return sum(terms) - max(terms)
    
    for n in range(2, 10):
      print(*max(permutations(range(1, n+1)), key=Evaluate))
    

    That's simple enough, and every self-respecting programmer should have Python installed.

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

Yay! Hello expert for the third time. Why is my performance so inconsistent? :(

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

speedforces A,B,C

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

Thanks for this great round that is full of ideas .

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

Автокомментарий: текст был обновлен пользователем artew (предыдущая версия, новая версия, сравнить).

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

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

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

I'm new to the platform, don't know how it works completely but solution like this should be illegal right? 218544590

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

might be one of the most trash solutions of A, but i solved it using scc (strong connectivity components). I built a graph where edge uv meant v % u = 0 and get all scc using Kosaraju algorithm. Then, if there is just one component, there's no solution; otherwise we can put the last component (in topological sort of condenced graph) into c-array and other components into b-array.

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

I thought those with rating above 2000 don't read whole problem and just go through the code just by reading Input/Output section. And that mistake costed me time and patience -_-

In first problem I submitted without knowing that I was supposed to print the size of array B & C (How dumb can I Be :( .. ) Still hope to get +ve delta

And can someone explain how to apply BS in D? I tried but it was too new way to implement that I failed. Please explain :)

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

My idea for Problem D was to first sort the intervals, then take the union of suitable intervals and finally for each point binary search to find the correct interval. Unfortunately I needed 10 more minutes to make it work. It got accepted now: https://mirror.codeforces.com/contest/1859/submission/218580066

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

Thank you for this contest!

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

Can anyone provide their lazy segtree implementation to D?

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

    Here

    Idk what happened but it was showing failed on system test but now it's accepted. Were the solutions rejudged or something?

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

    How did you use a lazy segtree ? What I did was processing the ranges by decreasing end and maintaining a dp which can be calculated with only a max segtree

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

      After figuring out the answer for a portal, update it's entire range [l, r] with that.

      Is there a way to solve it without lazy segtree? (not the set one though)

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

        I solved it with "only" a max segtree.

        Basically, each portal will be considered as [l, b] (because we can show it is optimal to jump on b, indeed, assume we don't, then any portal we will use to jump further than b could be used starting from b).

        Consider portals by decreasing end (and also consider queries at the same time, they are just special portals [v, v], also it's important to consider portals before queries in case of equality).

        Assume we know the answer for all the portals with a greater end than the current portal. Say the current portal is [l, b]. To improve our answer, we can jump on any portal [i, j] such that j > b and i <= b. The answer starting at the given portal is just the maximum of the answer of all such portals.

        We can maintain it with a max segment tree. When we just computed the answer for a portal [l, b], we chmax the position l with the value b.

        Now, to get the answer, we just need to query the maximum on the range [0, b].

        Here is my implem: 218572801

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

        You can solve it using dp and compressing in O((n+q) log n).

        I'm honestly surprised by the amount of people who used segtree.

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

The constraints for problem C were too lenient. it is not difficult to find an n^2 solution

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

Is problem C pure calculations or just intuition?

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

I don't know how my solution passed for C and D.

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

The solution to problem C, O(1) cpp void solve() { int n; cin >> n; vector<int> a={0,2,7,17,35,62,100,152,219,303,406,530,678,851,1051,1280,1540,1834, 2163,2529,2934,3380,3869,4403,4985,5616,6298,7033,7823,8670,9576,10544,11575, 12671,13834,15066,16369,17745,19196,20724,22332,24021,25793,27650,29594,31627, 33751,35968,38280,40690,43199,45809,48522,51340,54265,57299,60444,63702,67075, 70565,74175,77906,81760,85739,89845,94080,98446,102945,107579,112350,117260, 122312,127507,132847,138334,143970,149757,155697,161792,168044,174455,181027, 187762,194662,201730,208967,216375,223956,231712,239645,247757,256050,264526, 273187,282035,291072,300300,309722,319339,329153,339166,349380,359797,370419, 381248,392286,403535,414997,426674,438568,450681,463015,475573,488356,501366, 514605,528075,541778,555716,569891,584305,598960,613858,629001,644391,660030, 675920,692064,708463,725119,742034,759210,776649,794353,812324,830564,849075, 867859,886918,906254,925869,945765,965944,986408,1007160,1028201,1049533,1071158, 1093078,1115295,1137811,1160628,1183748,1207173,1230905,1254946,1279298,1303963, 1328943,1354240,1379856,1405794,1432055,1458641,1485554,1512796,1540369,1568275, 1596516,1625094,1654011,1683269,1712870,1742816,1773109,1803751,1834744,1866090, 1897791,1929849,1962267,1995046,2028188,2061695,2095569,2129812,2164426,2199413, 2234775,2270514,2306632,2343131,2380013,2417280,2454934,2492977,2531411,2570238, 2609460,2649080,2689099,2729519,2770342,2811570,2853205,2895249,2937704,2980572, 3023855,3067555,3111674,3156214,3201177,3246565,3292380,3338624,3385299,3432407, 3479950,3527930,3576350,3625211,3674515,3724264,3774460,3825105,3876201,3927750, 3979754,4032215,4085135,4138516,4192360,4246669,4301445,4356690,4412406,4468595, 4525259,4582400,4640020,4698122,4756707,4815777,4875334,4935380,4995917,5056947, 5118472,5180494}; cout << a[n-1] << endl; }

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

Amazing contest! Problems were high-quality and fun to solve. Thanks to kristevalex, artew, efimovpaul, induk_v_tsiane and all the other testers!

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

Автокомментарий: текст был обновлен пользователем artew (предыдущая версия, новая версия, сравнить).

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

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

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

Nice Contest!

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

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

Happy Birthday to MAX.

Video Editorial For Problem A,B, D and C.

https://youtu.be/wxtpQIPOHgE

Also I shared how I approached C during contest and was able to pass it but was not able to prove it.

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

Hi. First of all I'd like to thanks the authors for this great round !

I got TLE on problem C (I had a badly written $$$O(N^3 log n)$$$ solution). At that time, problem C had < 500 AC.

I spent 30 minutes to optimise my solution and at that time the problem already had almost four thousand AC.

I think that it is most likely because people wrote a bruteforce and guessed the pattern from it.

I have nothing against this (because I could have done it too, guessing is a tool that anyone can use in contests).

However, I just wanted to know what people think about such problems where writing a bruteforce and guessing a pattern makes it extremely obvious. Is it okay to have such problems in rounds on a regular basis ?

I'm not even sure of my own opinion but the thing is that I feel like the proof of such a pattern is way above the scope of div2 C while guessing it is way easier. idk

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

When I know the F was changed,I hadn't enough time to solve it.

So can this be unrated for me?

I have solved E&F after the contest.

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

Thanks for the nice contest ! And especially for problem D :)

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

I gave my first contest today, round 892 div 2 but my rating did not increase. I am able to see round 892 in unrated contest section in my profile. I was only able to solve one problem. can someone tell me why rating did not increase

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

Thanks for great round!

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

constructive forces

but the problems are good.

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

Fancy round! Though div2C could be easily solved in about $$$O(n^2)$$$ time by iterating over every mirroring of suffix and prefix (firstly, try mirroring every suffix, then try mirroring every prefix). Indeed, such solution gets AC: 218645309.

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

happy birthday Max, I wish you all the best. also I hope to get +20 at least in this contest

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

I wanted to ask why can we sort the array in question 2 without exceeding the time limit? Wont the time complexity exceed: let sum of mi=m O(t*(mlogm))=(2.5*10^4*(5*10^4*15)) =18.75*10^9, which is a lot more than allowed time?

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

I don't think C is a good problem.Because if the intended solution in the editorial is the only solution then it's a very good prblm and a deserving way to get AC in this prblm is to go through that approach . However , if you brute force in small constraints then you find a very obvious pattern and that ruins the prblm , that is why C has got these many ACs

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

Happy Birthday Max, sending you best wishes