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

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

Привет Codeforces! В 07.09.2023 17:35 (Московское время) начнётся Codeforces Round 895 (Div. 3). В этом раунде будет 7 задач, которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Мы постарались сделать приличные тесты — так же как и вы, мы будем расстроены, если у многих будут падать решения после окончания контеста.

Вам будет предложено 7 задач и 2 часа 15 минут на их решение.

Штраф за неверную попытку в этом раунде будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в пяти рейтинговых раундах (и решить в каждом из них хотя бы одну задачу)
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Задачи были придуманы и подготовлены: Alexdat2000, FairyWinx, sevlll777, Vladosiya, и MikeMirzayanov.

Также большое спасибо:

  1. Vladosiya за прекрасную координацию раунда, и помощь в подготовке и балансировке набора задач.
  2. MikeMirzayanov за платформы Polygon и Codeforces.
  3. Ormlis за чёрно-красное тестирование раунда.
  4. zwezdinv, BledDest за красное тестирование раунда.
  5. Sokol080808, diskoteka, Sweezy, vladmart, Kniaz, Tima, Riblji_Keksic, 74TrAkToR, pavlekn за жёлтое тестирование раунда.
  6. moonpieXXIV, gs20036, Kolychestiy за фиолетовое тестирование раунда.
  7. martin0327, tnaito, no_mind, Pa_sha, JuicyGrape, ctraxxd, ezdp, FiniteMoves за синее тестирование раунда.
  8. NerfThis, _SADIEM_, YudoTLE, sayed_4 за циановое тестирование раунда.

Всем удачи!

UPD: Разбор

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

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

I enjoyed the problem set during testing, good luck to all the participants!

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

Me getting +100 tomorrow after solving 5 problems

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

Problems' quality are just great and fun to be solved UwU

For all participants, May the odds be ever in ur favor❤️

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

As a tester , I can assure that this is the most balanced div-3 problemset I have ever faced and I recommend to read every problem

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

As a tester, I hope you will enjoy this incredible contest

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

I think the problems are nice. Good luck to participants!

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

Good luck!

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

Big chance to reach green tomorrow

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

I hope I don't get hacked again

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

I will try to solve all :>

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

As a tester I recommend reading all problems. All problems are really fun, good luck!

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

OMG , Janmashtami round

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

Hope to become Cyan in this contest :)

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

Good luck!

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

MY first unrated Div 3.

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

Hope to reach 1000 in this contest.

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

This is no longer rated for me.. Weird bittersweet feeling

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

I am excited to participate in this contest. Good luck for all participants.

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

expecting high quality of problems from Vladosiya as usual

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

Last time, my sister was angry during contest and this time Shri Lord Krishna will be :(

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

Good luck to everyone! I really hope that I get specialist back

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

very balanced contest, loved it.

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

$$$t$$$ test cases forces

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

problem C is such a troll problem

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

NumberTheory-Forces

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

Any hint on how to solve problem E?

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

great contest!

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

How to solve E without using segment tree?

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

Problem B explanation was not good, almost wasted 1.5 hours to understand

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

How to solve G? If we have at least >= 20 non-unit elements, the answer is obvious. However, i still don't understand how to find the answer if there are only k < 20 non-units, even in O(2^k) or something like this...

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

Was it just me who wasted 5 min on problem A because of this:

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

How my brain processed Problem C:

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

Thanks for the contest. It was really amazing.

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

I really liked the problemset

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

it feels so good after solving E.

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

Amazing contest! Problems were nice and fun to solve. Thanks to Alexdat2000 FairyWinx sevlll777 Vladosiya for the round.

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

amazing contest!! I feel G is much more easier than F. Maybe its just my skill issue on graph problem. haha

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

Have someone did F with path compression ?

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

Quick Editorial:


Problem A

Problem B

Problem C

Problem D

Problem E

Problem F

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

Hey cf folks, looking for a coding friend who wants to upsolve with me, would really help if we could discuss answers after a contest gets over.

Also since the editorial is not out yet, can anyone explain me the intuition for problem C ?

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

    If l != r and r is at least 4 then one of the numbers is 2 and the other is floor(r/2)*2-2, this works. If l != r and r is less than 4 there is no answer

    Otherwise we need to find a divisor of l that is not 1 or l, we can bruteforce until sqrt(l) or use the Sieve of Eratosthenes to factorize l. If l is prime then there is no answer

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

      Still not able to understand it >.< I guess I'll leave it at that

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

        Apologies, I realized I didn't explain properly.

        If l = r then the sum of a and b must be equal to l, so if l is prime there is no answer (suppose there was, then there exists c >= 2 that divides a and b and therefore divides l as well which can't happen.) Otherwise we can choose a = min divisor of l that is not 1, and b=l-a.

        Otherwise, notice that a+b >= 4 because a and b are both at least 2. So if r < 4, there is no solution. Otherwise there exists a solution. Consider a = 2. We can choose b such that b is even and a+b is either r or r-1, assuming l != r (we handled the other case above), which is where b = floor(r/2)*2 — 2 comes from.

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

In problem D, I changed n,x, y type from int to long long and it got accepted. How could this be possible? [n maximum is 10^9]

Wrong answer here

Accepted here

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

    You have the line "using namespace std;" so when you call lcm(x,y) with x and y as int it ignores your custom lcm function and uses std::lcm(int,int) as that matches better, but that returns an int so it overflows.

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

A: The answer will be cd(abs(a-b), 2*c) because you have to move half the difference from the biggest vessel to the smallest one. and this will take you cd(abs(a-b)/2, c) moves.

B: Each trap forces you to be back past it after s-1 seconds. In that time you can move (s-1)/2 units to the right of that trap and sitll have time to return. Each trap puts on such restriction on your trip, so you just iterate over the traps and do ans = min(ans, d+ (s-1)/2)

C:If l and r are at least 4 apart, there is a multiple of 4 between them, lets call it k, and then k/2 is even, so we can set x= k/2 and y=k/2. If l and r are less than 4 apart, we can brute force all divisors of l, l+1, l+2 .. r. And then if d | l, we can return x = l — d and d. This will always find a solution, because if gcd(a,b) = g, and a+b = k, then g | k. So the answer will always be found among the divisors of the numbers between l and min(r, l+4)

D: You want to put the biggest elements of the permutation of multiples on x, and the smallest on multiples of y. You can ignore the indexes that are multiples of both. However, you can't calculate this naively. because n= 1e9. However, you can use triangle number sum n(n+1)/2. the number of multiples of x that are not multiples of y is n/x — n/lcm(x,y) = k. so do n(n+1)/2 — (n-k)(n-k-1)/2. To get the multiples of x, and do -(y-n/lcm(x,y))((y — n/lcm(x,y))+1)/2 to subtract multiples of y.

E: The array never changes, so we can calculate an XOR prefix array. After this we can calculate the XOR of all the ones-position in the array and all the zero-position in the array.

Then, whenever we are queried, we can just set ones^=prefix[l,r] and zeros^=prefix[l,r]. That is, we set our ones and zeros XOR counters to XOR the XOR of the element in [l,r]. The reason we can do this is because when we invert [l,r], we remove all the ones from 1, and add all the zeros. However, removing the ones is the same as adding the ones because every element is its own inverse under XOR. Same logic applies for zero

F: All the nodes with indegree zero, we can remove with no issues, because no one is afraid of them, so we lose nothing by removing them early. After we've done this, there might be new nodes with indegree zero, so we remove those as well (and add to answer in the order we remove them).

After we've removed all the nodes with indegree zero, there will only be cycles left. This is because every node here has outdegree 1 (they are only scared of one other animal).

So we can go through the cycles and find the animal with the least cost, call it s Then we go through the cycle and remove all elements in order, starting with A[s], and ending with s. That way we get twice cost of all the animals except s (which has least cost, so this is optimal).

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

Hi

Just checked out the problems and noticed that problem F was 99% same as abc256E

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

Problem A: does not have to be an integer

Problem B: best illustration in contest

Problem C: even number, not 2, odd number, not prime, not 1

Problem D: sum top for x, sum bottom for y, duplicate LCM

Problem E: Lazy Segment Tree (but not enough time)

Problems are enjoyable! Thank you guys for the contest!

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

I lost D due to a typo long long -> long T_T

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

I solve C like this 222257731.I don’t want to discuss in categories(because I got Time limit exceeded :(

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

For problem E, I tried to solve it using the segment tree here. I pre-compute the XOR of the entire array a and store the precompute XOR of those values where s[i] = 1 in the tree. So then XOR of those that are zeros in s equals to all ^ one. The time complexity should be $$$O(max(q, n)logn)$$$, but I got TLE. Can anyone tell me what I did wrong?

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

I made video explaining problems A&B&C&D : https://youtu.be/g7OJ3GVzIhM

I thought it would be useful

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

That's very good contest i liked how does E work i thought that E is segment tree but i did learn a knew thing while thinking that you can make prefix xor , thanks for the contest.

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

In E I did sqrt decomposition lol

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

Does E require square root decomposition ??

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

Proper Div 3 round after a long time.

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

I didn't expect to learn something new in Div. 3 contests (the lemma about Functional Graphs, I skipped my theory classes :/), so thanks a lot.

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

Video Editorial For problem A to G.

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

Did somebody notice , that in todays G 1<=a[i]<=1e9 , but in examples they took a[i]=0 in some places .

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

My worst div.3, I solved only A-D(lately, beacuse of C) in contest, upsolved F. For me: C>D, E>F. But I couldn't solve F in contest. Hope better next time.

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

I'm not rly good at maths can someone plz explain how did he solve D by steps

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

I want some hints for problem F. If we make a directed edge graph out of the given things, with

$$$a- \gt b$$$

meaning b is afraid of a, it would mean we actually have to implement toposort when the graph is acyclic. The problem arises when the graph become cyclic.

In that case we observe that for a cycle say,

$$$a- \gt b- \gt c- \gt d- \gt a$$$

, if we start from anywhere, let us say, from d, and go in the reverse direction of the edges, (i.e d->c->b->a), we will get the

$$$profit = 2d+2b+2c+a$$$

. In other words, if we start at node x such that

$$$x- \gt y$$$

is an edge in the cycle, the profit we get is : profit = 2(Sum of profits of all the nodes) - y. This hints that we need to keep track of all the cycles in the graph.

Further we observe that the In Degree of any node will not be greater than 1, It means that two cycles cannot have any node in common, and also any two cycles are disconnected (it can be proved by contradiction). So now the problem reduces to finding the strongly connected components of the graph (as the strongly connected components will only have cycles in them), and then to track the minimum of the nodes present in the cycle.

Is there any efficient way to do this?

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

    Hey you're on the right track. Don't make the question too complicated tho. As you said indegree and cycles are important information for this question. Take some of the given samples, and try to reduce them into solvable graphs.

    Hint :- As each vertex has exactly one outgoing edge, so any cycle if present will be a simple cycle. Also each vertex will always have exactly one outgoing edge, so maybe solving for a cycle isn't that hard.

    You'll get the solution if you try to find a way for the given samples. I solved sample 2 and 6 when I did the question.

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

    My solution is Change the problem like this: if we sell Animal i there is a cost sum(C[j], for all animal j that afraid of animal i). Using priority_queue you can sell the animal(i) whose cost is minimum currently. And update cost of animal a[i] and push this to priority_queue.

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

    Kahn's toposort algorithm is still useful — it can give you an ordered list of nodes that aren't in cycles (so can be sold for 2*C). You can then just calculate the cycles for any nodes not in that list (using a simple dfs as there is only one option at each node).

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

How to do G? I am totally clueless. Please help.

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

.

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

    I'm not 100% sure, but I think the real issue is that your n inside function init is greater than the N you used to declare arrays. This can lead to overflow problems and unknown errors, including Wrong Answer. Your submission got AC when your n is smaller than N.

    Actually, your code always gets RE on my computer. It's a little strange why you didn't have this during contest, maybe because you didn't enable O2 optimization when you debugged locally? Specify -O2 can sometimes help expose some issues like overflow :D

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

suck the B problem

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

I gave the contest and solve 2 questions but still i am unrated and the this contest is showing unrated for me i don't understand what is this if anyone has idea about this please tell me

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

Hope to become an expert, good luck

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

Cannot understand why people are jumping to segment trees to solve problem e. It's a div3 e, not div2 e!

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

Happy that I solved first 5 problems in this contest , but could have solve little faster to get good rank. Hope to be Cyan again after rating update.

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

Good contest hope pupils touch cyan their first time after rating

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

I put long long instead of long double when doing G (was working with log10) so got WA when rejudge, weak pretest :v but overall i enjoyed the contest.

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

Can someone please identify the problem with my submission for D? I'm pasting it below for easy reference. Thanks.

222341350

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

It was a very cool round, thanks to the creators!

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

Indians are rocking everywhere.

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

Good Luck Everyone for System Testing.

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

Why is this round being retested now?

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

I have got a skip on this problem : 222280755 for the problem 1872E

this template of code is shared with me and my friends as we all are in the same training

and the segment tree code is also a template, you can see my previous codes, all of them with the same template, so please give me the points back