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

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

Привет, Codeforces!

В Feb/23/2024 17:35 (Moscow time) состоится Educational Codeforces Round 162 (Rated for Div. 2).

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Иван BledDest Андросов, Максим Neon Мещеряков и Роман Roms Глазов. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD: Разбор опубликован

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

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

Good luck to everyone!

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

Such a short and clear announcement I hope problems statements be like this too!

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

Hope able to AK this round

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

Good luck to everyone! (please upvote i need contribution)

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

Excited to get to Expert

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

Hope to reach 2024

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

I think the title should say [Rated upto div2] instead of [Rated for div2]

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

My last contest in this winter vacation

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

good luck from good duck !!!

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

Score distribution?

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

Who tested?

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

Educational rounds are mathforces af, thats a skip

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

Enjoy the contest!

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

stay up to late again:)

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

Small and clear announcement. Hopefully we will enjoy this contest. </>

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

Good luck everybody. Hope to get positive delta :)

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

Missed opportunity to name problem C. as "Find C"

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

Do we write outputs for each test case as it comes or all the way at the end?

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

Finally, Goodbye 2023 has a worthy competitor.

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

It's like Div 1.5

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

B>>>C

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

Speedforcing abcde

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

B < A

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

problem D :(

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

E too easy to be an E, swap D and E

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

cheaters ruined the contest again :(

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

Nice problem F! Thanks!

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

    How to solve it? My intuition is that we will perform 2nd operation at most once. Since number of 1s stays constant , we will try to merge 1s as close as possible.

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

      That's it! (I didn't realize we needn't do the 2nd operation twice in the contest QWQ)

      When we perform the 2nd operation only once, we can consider on the reversed string. We can try all positions for the highest bit, and binary search on the final length of the string ignoring leading zeroes.

      If the positions of the highest bit and the lowest bit are determined, the greedy solution is to put all 1 outside to the last few 0s in the interval, so the prefix of some length doesn't change. So we can use hash or suffix array to compare the prefixes, and then the best starting position can be determined.

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

    But I think it's hard to write it.

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

I finally joined the dark side, selling my soul to Atcoder!

If you want to build intuition and upsolve problem D without looking at the editorial, try out 1901D : Yet Another Monster Fight. I've added hints as well.

A major hint for this problem:

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

after getting 15 WA on problem C, I wished contest end earlier.

screwed up, going gray again

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

in B is it not optimal to kill the nearest monster?

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

hint for D pls

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

Why so tough time limit in E?

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

how to approach B?

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

    Loop from the closest monster to the farthest (you need to take only the absolute value of all monster positions and then sort them), but you need to know each monster's health after the sorting, so you need to use something like a vector<pair<int,int>> where the first value is for position and the second value is for the index of that monster corresponding for its health . Now just loop from the closest to the farthest and sum their health and check how many rounds you need to get rid of the current sum, Rounds_required = ceil(current_sum/k).

    If at any time the rounds required are bigger than the current monster position, then we can't kill that monster so break and print no

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

.

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

Need More Practice for Educational Rounds. Btw Can anyone tell me the approach for C.(B>C)

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

Very nice problems

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

How to hack others?

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

any hint for problem c????

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

Typo in problem D's tags: https://imgur.com/TvwOJcP

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

Did anyone recognize C was 1856B

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

A: Let L=the minimum position of i such that a[i]==1, R=the maximum position of i such that a[i]==1, the until occurences of 1 become a single block, R-L will decrease 1 if you do operation on position R, otherwise it will not decrease. So the answer is (R-L)-(cnt-1) where cnt is the count of occurences of 1.

B: For each 1<=i<=n we need sum(j:abs(x[j])<=i)(a[i])<=k*i to kill monsters with distance <=i in i turns.

C: If L==R answer is no. Otherwise, for each a[i]==1 we need some j such that a[j]>1 and let a[i]+=1, a[j]-=1. Then we need sum(i:a[i]==1)(1)<=sum(j:a[j]>1)(a[j]-1). We can check this condition in O(1) by prefix sum.

D: Assume slime i is eaten by some slime to the left (the other case is similar), and all slimes used to eat i will form an interval [j, i-1]. So we need to find the maximum j such that sum(j, i-1)>a[i]. If j==i-1, slime i-1 can eat slime i directly. If value of a[j...i-1] is not all the same, then there will be a largest slime which can eat all other slimes in range [j, i-1] then eat slime i. Otherwise, all slimes in [j, i-1] have the same size and cannot eat each other, and slime i-1 is not larger than slime i. So we need to extend this interval to the left to find some k such that a[k]!=a[i-1] (if such k exist).

E: Small-to-large merge. Let dp[u][c]= (the number of nodes v in subtree of u, such that v is color c, and nodes on the path from u to v (except v) are not colot c). Then the number of valid paths with lca=u is sum(v1)(dp[v1][color[u]]) + sum(v1,v2,c)(dp[v1][c]*dp[v2][c]), where v1,v2 iterates over childs of u, c iterates over all colors on subtree of u, and v1<v2, c!=color[u]. The first term means valid paths start from u, and second term means valid paths start and end in subtree of u. To calculate the value we have dp[u][c]=sum(v: child of u)(color[v]==c) (if c!=color[u]), dp[u][color[u]]=1, we can maintain imformation in std::map and merge them small-to-large.

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

Can anyone please tell me why does this code won't work for problem C :(

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

B >>> D > E > A > C

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

Anyone who got WA on test 2 at problem D, then managed to solve it? What was missing? I did a binary search on prefix sums while checking for the existence of different elements using two segment trees (minimum != maximum). I got WA on test 2, and I couldn't find one where it was not working.

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

In problem D sample input and ouput it is given in the third testcase that 2 2 3 1 1 will give an output of 2 1 -1 1 2 but cant slime 3 be eaten when 2 eats 2 and then eats 3. Making the expected output 2 1 2 1 2 or am I going wrong somewhere

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

F is beautiful! Too bad I only managed to solve it a few minutes late lol

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

Can someone hack it? 247947284

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

247976858 Can you give me test case wrong ? My program WA on test 2 (Problem D)

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

Can anyone find out the my mistake Thanks[submission:247947411]

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

COULD YOU MAKE SAMPLES IN TASK C BETTER?

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

I think problem D can be solved using binary search

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

Do anyone know how can my O(n * log(n)^2) solution for problem D got TLE, since n * log(n)^2 is only around 10^8

247977945

Thank you so much

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

Why does C have so many hacks?

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

What is an "easy" solution of problem E? I solved it exactly as this problem.

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

    I also solved it using this idea, some people have solved it using small-to-large merging.

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

    I just saw your comment. I already posted my solution elsewhere but here it is again.

    It consists in one dfs. The idea is to keep track of which colors were accessible before on the dfs tree, with multiplicity. When branching, we set the current color to multiplicity = $$$1$$$ because it then loses its multiplicity (the path needs to be beautiful). But then it needs to regain its old multiplicity $$$+1$$$ when we end the dfs.

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

tourist C hacked

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

D: For each index ,I gonna binary search on the answer. So consider position i, we have to check if after x seconds, we can eat this slime or not.

Im computing the left side first, that mean we considering only from 1 to i-1.

In the position i and after x second, there are two case:

  • All x-1 slimes to the left of it are the same , so the process can make the biggest slime is one of them.
  • Otherwise , the process after x seconds always make one slime that equal to the sum of all x-1 slime to the left of i-th one (this pretty obvious because at any time, you always exist a biggest slimes that near to another), then we just need to check that sum is bigger than size of i-th slimes or not

After finishing the left side, we do the same on the right side and compare the answer 247990076

E : I saw a lot of simpler solution for problem E (merge set/map on tree, etc...). Anyway, I have another technique for E that is "Auxiliary Tree", which was very useful and generic in some specific type of problems. You can find it here : https://mirror.codeforces.com/blog/entry/76955. This problem is similar to E, which you can try to solve it first : 613D - Kingdom and its Cities. You can read my solution for E here : 247980215.

Bonus

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

What is the hack on C? Asking for a friend..

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

Unfortunately, hacks for C were judged incorrectly due to a very peculiar case of UB :(

We are sorry for that, all hacks have been rejudged. The solutions during the contest were judged correctly, so this affected only the hack phase.

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

This comment has been deleted.

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

247954847 How this solution is getting TLE?

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

it may not appropriate to write such comment but

There is a case where my code for C is failing, i tried a lot to debug even stress testing but still couldn't found anything! it's failing on token 59831 on testcase 3

i don't know what's minor mistake i'm making 247924659

can anyone help me ?

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

Can someone explain why I got TLE 247937101

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

Approach for solving Problem E using auxillary tree and DP.

Suppose for each color $$$\textbf{c}$$$ we perform a $$$\texttt{dfs}$$$ on the tree and calculate number of nodes in subtree of node-$$$i$$$ of color $$$c$$$ such that none of it's ancestor has color $$$\textbf{c}$$$. Now we divide our answer in two cases:

Case-1: Node-R has color c
Case-2: Node R has color c

But this will take $$$O(n \cdot n)$$$ time. To optimise this, we compress the tree in a way such that we only take nodes of color $$$\textbf{c}$$$ (and some extra nodes less than equal to number of nodes of color $$$c$$$ in number) without losing any information that we could obtain for any node of color $$$\textbf{c}$$$. Now we can use the same logic without any problem.

For each color our complexity would then reduce to $$$O(\text{number of nodes of color c})$$$ (ignoring the extra $$$\log$$$ factor that comes because of $$$\text{lca}$$$ and $$$\textbf{sorting}$$$. Here is my submission for the problem.

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

is problem D prefix/suffix sum problem? then using binary search on pref(left), suff(right) then take lower..? but how to handle case where having same size adjacent?

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

    I took care of this case by first going through the whole array and extracting the adjacent subarrays of same values (in the form of a vector of pairs (left index, right index)). Then, when binary searching, I would call the condition not met whenever the currently considered subarray lied in one of the precomputed "adjacent subarrays of same value".

    To handle this with a good complexity, I used another binary search to find the good (left index, right index) candidate with which I should check if I am inside or not. It's like geometry, so maybe there are easier ways to do so.

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

      To make the implementation easier, you could use DP. Define $$$dp[i]$$$ to be the index of the leftmost consecutive identical element that ends at $$$i$$$.

      • If $$$a[i] == a[i - 1]$$$, then $$$dp[i] = dp[i - 1]$$$.
      • If $$$a[i] \neq a[i - 1]$$$, then $$$dp[i] = i$$$.

      Using this DP array, how to check if the range $$$[l, r]$$$ has identical elements? Just check if $$$dp[r] \leq l$$$. If yes, then the range has identical elements.

      Now, you can do a binary search on $$$[0, i - 1]$$$ to figure out the answer.

      Submission

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

Any small counter testcase for my C 1923C - Find B; submission 247973573 as well? I have used all the TCs posted by AVdovin and 29logN

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

Hello Everyone, Hope Everybody is doing great. I am stuck at problem C, can someone help me, what's wrong with my code

248047400 this code is after i have take the input array

for(int i=0;i<n;i++) { prefix[i+1]=prefix[i]+a[i]; } while(q--) { ll l,r; cin>>l>>r; ll k=r-l+1; if(k==1) cout<<"NO"<<endl; else { ll sum=k/2+2*((k+1)/2); if(sum<=prefix[r]-prefix[l-1]) cout<<"YES"<<endl; else cout<<"NO"<<endl; } }

According to me it should be correct,but failed at some 58k token.

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

Why are red coders visible as rated contestants in the final standings?

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

Video Editorial for problem C : YOUTUBE EDITORIAL LINK Audio : English

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

unrated contest pleaseeeeee!!!!

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

Hey folks, can someone please help me figure out why my solution for C fails in the second test case.

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

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

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

Who else failed the system test for problem C because they used 2e5 instead of 3e5 for the array size? (And somehow passed the pretests?)

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

lovely contest became specialist after a lot of struggle