Hello!

I'm glad to invite you all to Round 576 which will take place on Jul/30/2019 17:35 (Moscow time).

There will be 6 problem in both divisions.

Round is based on Team Olympiad in Computer Science Summer School. It is (yet another) summer school for schoolchildren organized by Higher School of Economics and "Strategy" Center in Lipetsk. Almost all the problems are authored and prepared by teachers and teaching assistants in CSSS: Um_nik, Burunduk1, I_love_fake123, MakArtKar, Villen3tenmerth, Aphanasiy, Gadget. One of the problems is authored by Merkurev (just because we are friends :) ). One more problem for the round was added by KAN.

I would like to thank KAN for CF round coordination, I_love_Tanya_Romanova, Merkurev, Rox and tractor74.ru for testing, and Codeforces and Polygon team for these beautiful platforms.

Scoring will be announced.

Upd: We added one more problem to div.1 contest, now both contests have 6 problems (4 in common). The round is not combined, if it were, I would write "combined" in the title.

Scoring distribution:

div2: 500-750-1250-1750-2500-3000

div1: 500-750-1250-1500-1750-2250

Congratulations to our winners!

div.1:

1. Radewoosh

2. tourist

3. mnbvmar

4. Benq

5. pashka

div.2:

1. ChthollyNotaSeniorious

2. Honour_34

3. ldxcaicai

4. shogunator

5. Yatsumura

Editorial won't be published.

Auto comment: topic has been updated by Um_nik (previous revision, new revision, compare).Wow wide range of writers ( LGM to pupil )

Looking for a crazy contest :P

Guess, Mike is a part of "Codeforces and Polygon team".

Sorry, I shouldn't have made such non-sense comment. I won't repeat this again. :)

HHAHAHAA

Well, he is not saying that they didn't thank Mike, he is saying that they didn't

speciallythank Mike.Will there be stories about Um_nik's teal hair?

I also want to know something about his hair,ha-ha.

Why You forgot to thank specially to MikeMirzayanov for Codeforces and polygon platform? He can block your account chinese!

Oh~,long time without a div1+2 conbined contest.

I was excited as soon as I saw this contest appear in the list of upcoming contests.

Hope the problem ststements will be as short as the announcement!\XD

The last Div.1 + Div.2 contest was Codeforces Global Round 4 (and the last Codeforces Round was Codeforces Round #513 by Barcelona Bootcamp (rated, Div. 1 + Div. 2), 10 months ago), but is today's contests Div.1 + Div.2? I think only the notice says that way, and these are two separate contests.

No, there have been many Div 1 + 2 combined rounds, just not labelled as such. The Mail.Ru rounds and Global rounds were all Div 1 + 2.

Oh- I missed that. I thought only Codeforces Round #NNN, but you are right. I should edit the part of that. (And anyway, what do you think about my question?)

Yeah, today's round is not Div. 1+2 as per the convention I have seen and they should omit it from the blog post title.

I was saying this out of strange after seeing it.

I wanna get high rating.

looking forward to getting a high rank，last few contests I didn't perform well

points or plus ???

Points because this is Div.1 and Div.2 Round, neither Div.3 Round nor Educational CF Round..

thank you

Oh! Kizaru San, when are you going to Wano ?

hmmm, i will, if Akainu agree

Anybody knows the difference among div.1+div2 and 2 separate rounds?

Div.1 + Div.2 Round is

Onecontest in which Div.1 participants and Div,2 participants participate altogether and 2 seperate rounds are literallyTwocontests in which participants participate in his own Division.Why results of div1 and div2 is n

I think Um_nik has not much experience to make a good contest, so I will not write this contest.

Oh no, please write our contest!!!!!1!

what happened to your hair ?

I

~~died~~dyed themGood to know :)

MWM, for a moment I thought that after solving many problems your hair started changing its colour!

Btw, I think is better if you dye it one part red and the other black (just like nutella)

You look like a combination of Limmp and Ramzes666.

He want to say he's the king of cyans, since he worth more than 1000 cyans

Um_nik is the new exchange coin, he worths 1024 cyans, 256 blues, 64 purples, 16 yellows, 4 reds, one nutella.

Usually when one puts

`+`

between "Div. 1" and "Div. 2" it means a combined round, and names for posts for regular separate rounds don't contain a substring`Div`

at all. You explained the separateness of the round in the update and wrote explicitly that each division has 6 problems (4 in common), but anyway I suggest not to use the`+`

sign to denote separateness next time(s), otherwise someone will be confused.Yes, I understand the confusion. I didn't know that there is a fixed convention, sorry.

How long the contests are?

2 hours. It's on the contest page.

"We added one more problem to div.1 contest" <3

It will be easier than all others. At least in my opinion.

Which problem was added?

A

top hue

why start at 17:35, why not at 17:30?

It may be farfetched, but (because) it's usual start time of the contest. So, is there a reason why the competition must start at 17:30?

It's good to think that the contest starts at 17:30, because of the registration.

Is it rated?

Obviously ! <3

My teacher told me not to assume anything beforehand

Probably not. You know, rounds by Um_nik are never rated.

hello :D I have a doubt. What is a hack?

When you are able to prove some submission wrong by providing a clever test case whose output is wrong according to tester code/verification of output by the system. Hope it helps:D

thank you

At codeforces , you can see the code written by others. So after you see others code which have passed the pretest, if you think there may be some data that his or her code may give the wrong answer, you can submit a piece of data ,and if his or code give the wrong answer , that means you hacks successfully, and you will get point, otherwise, you will loss point.

thanks

gl & hf all

the number of registration in div.2 must be over than 10k before contest!

Scoring doesn't seem to add up for common problems. Interesting...

It would be a good contest excited to solve problems.

I can see there's nothing strange about the performance of HanwhaEagles in this contest.

After a long time you see so many full scores in Div 1 and hacks too, indicating "Author's mind is weak" Um_nik

Spoilerhttps://codeforces.com/blog/entry/51770?#comment-357097

What is your problem with full scores?

However hard I try, I can't get it right. My mind is weak. But seeing so many full scores makes me feel Author doesn't have hard/interesting questions.

Your handle doesn't check out.

In general, it's not good to break ties between too many contestants at the top just based on time. Doesn't matter much in a CF round compared to World Finals of Serious Competition, though.

Where is tag "square round"? (576 = 24*24)

How to solve D

For queries of type 2 maintain range max query and assign proper value after all queries. Code: https://codeforces.com/contest/1199/submission/58010154

I used Lazy propagation on a range max segment tree (though the range max is not required).

Please find my submission here.

This contest made me sad

How to solve Div2D?

Process queries in offline mode. Hint: we don't care what queries of type "2 x" there were before the last query "1 p x" for every p. We just need to take the maximum of the x in the last "1 p x" query for a certain p and all x's from queries of type "2 x" that occurred later. Suffix maximums may be calculated easily in O(n).

So Range Max segment tree was an overkill. :|

How to solve D?

Segment tree.

It can be solved without using Segment Tree

OK,I know.

But Segment tree is easier to think:D

I used 10 minutes to solve this problem with it.

I also tried to solve using segment tree but had some bug in my code :(

How to solve B :D

l^2 — h^2 = 2hx. Find x. Because length of segment A-top of flower remains same.

how you came up with this equation?

Pythagorean theorem

from the given image, we can see A^2 + L^2 = (H+A)^2

then by simplifying the above equation A^2 + L^2 = H^2 + 2HA + A^2. then by eliminating A^2 from both sides L^2-H^2 = 2HA then A = (L^2-H^2) / 2H

Makes sense. Thanks.

Please how did you come up with this. I had to use cosine rule which took me time.

I think this is an isosceles triangle :3

Which triangle is an isosceles?

If you connect the line from two flowers like a drawing for you to create a triangle. Calling the three vertices of that triangle respectively A, B, C with B and C are respectively flowers. I noticed that triangle ABC is an isosceles triangle

And ABC is an isosceles triangle with AB = AC. You can easily find :3

And how did you notice that?

Because length of segment A-top of flower remains same.

A^2 + L^2 = (H+A)^2

Use binary search to find A. For me binsearch is simpler than separating A in that formular.

Is it really that difficult in the end it is just ( L^2 — H ^ 2 ) / 2 * H

i think E can be solve by blossom algorithm,

but i dont know how to implement in O(V sqrt E). Can you give me some link, please?

There is no way to find the maximum matching in general graph in $$$O(V\sqrt{E})$$$. As far as I know, the complexity of the fastest algorithm for this task is $$$O(VE)$$$.

This is my solution for E (I cannot implement it in time :( ):

I can prove that $$$S$$$ is an independent set we need to find.

Suppose that $$$S$$$ is not an independent set. That means there are two vertices $$$u, v \in S$$$ such that there is an edge $$$(u,v)$$$ in the given graph. However, that also means we can add $$$(u,v)$$$ to the matching $$$M$$$ (contradiction). Therefore, $$$S$$$ must be an independent set.

It is easy to see that $$$|S| > 3n - 2|M| > 3n - 2n = n$$$, therefore $$$S$$$ is an independent set we need to find.

awesome proof.

My solution for 1C/2E is in $$$O(TV)$$$。

First put all the points into a set.

When you read an edge, if its 2 endpoints are all in the set, put the edge into a vector and delete the 2 endpoints.

In the end, if the size of the vector >= n, we can puts "Matching".

If the number of remaining points >= n, we can puts "IndSet". So it's $$$O(V+E)$$$

per a query.Very nice. I was trying to figure out something similar but I was too stupid and also there is an Edmonds blossom algorithm, so I ended up coding that...

On the other hand, when I was not able to clearly see all these things during the contest I could have ended up coding something very similar, yet incorrect, which resulted in some tle's and wa's among submissions. When I checked them, they seemed to do something that you described, so I don't regret.

just use wiki ;)

https://en.wikipedia.org/wiki/Matching_(graph_theory)#Maximum_matching

[x](https://en.wikipedia.org/wiki/Matching_(graph_theory)#Maximum_matching)

x

Hm... (testing links syntax; seems there are bugs in processing brackets inside the link)

Use

`a href`

, Luke.A Vietnamese competitive programmer gave me an article that presents an $$$O(\sqrt{V}E)$$$ algorithm for the maximum matching on general graph

Gabow (2017)

is div2 E is a coloring problem(vertice coloring and edge coloring)?

DP state for Div2 F?

Yes. It's in $$$O\left(n^5\right)$$$. $$$f(x1,y1,x2,y2)$$$ mean the answer to the range $$$(x1,y1)$$$ to $$$(x2,y2)$$$.Use memorized search to maintain the answer.

Can you please explain how O(n^5) is passing? If we directly calculate then it's 3*10^8 computations. The more complicated calculation would be — (50*(51)/2)^2 (states) * 2 * ~25 (dividing each rectangle into two rectangles, horizontally and vertically.

This is easily crossing 10^7 computations and almost touching 10^8. Generally, 1 second means less than 10^7 computations, right? (Help me out with that please, could never get a proper idea)

With reference to my submission — F

On a side note, hot to make comments look pretty? I know there's bold and italics but for example, how to use superscript?

I was in despair until I found that $$$O(n^5)$$$ solution can pass 2F/1D.

Div1C: https://codeforces.com/contest/1148/problem/G

How this two problems are connected?

Hi sir may I know if the random solution in Div1 F will fst?

There exist random solutions which will get OK.

OK Thanks.

Do you mean something provable?

No, I mean that we don't know how to create tests against some randoms

Waaaaaaat, even this shit? :/ 58013316

Well, OK, I've just started wondering if it is simply correct... Any ideas anybody?

I try to use the same way as this guy, But I sometimes Get WrongAnser. So this solution is incorrect.

Sound reasoning

0.5 to counter some determine but slow and still let random pass!

The problem isn't the TL, you can pass with $$$100$$$ ms (58034608). If you want to avoid this kind of incident, then the best way is to not have F in the contest.

I am wrong.

Imo $$$(20~choose~10)$$$, but I'm not sure.

The only one difference is that in one, you are asking to find matching, and in other, you have to find set with at least one edge from each node. These are quite similar things. In fact, solution of how to find matching is described in the editorial of Gold Experience.

Gold Experience, you say?

Ok, you are totally crazy, don't see a point in continuing this conversation

Div1C одна из лучших задач за последнее время, спасибо автору.

Validator 'val.exe' returns exit code 3 [FAIL Expected integer, but "#include" found (stdin, line 1)] close (what???)

Will the random solution in Div1 F fst?

58029804

Hope it won't. :D

If this submission can be accepted, it's really a bad problem.

It seems that it's already a bad problem.

well, this submission has got passed https://codeforces.com/contest/1198/submission/58013316

how to solve D, I wrote some stupid n^6 dp and thought it would pass, of course it did not pass

Observation 1: An optimal solution exists by only painting squares

Observation 2: An optimal solution exists such that no two painting regions intersect, otherwise we can merge them into a bigger square.

Thus we can do a naive dp using submatrix as states, divide horizontally or vertically for transferring.

Can you explain observation 1 a little bit please?

If I paint a rectangle with size $$$w\times h(w>h)$$$, it costs $$$w$$$, if I paint $$$w\times w$$$ instead, it still costs $$$w$$$ and it won't be worse.

If we paint a rectangle of size $$$n\times m$$$ where $$$n<m$$$, we can expand it to an $$$m\times m$$$ square which only makes the solution better.

can you prove your observation using another argument like for a given construction can you provide a way to convert a rectangle submatrix to some subset of square submatrices while maintaining the same cost . i can't seem to prove both of your observations simultaneously using your argument , suppose i give you an optimal construction then i can choose larger side of a rectangle as a square and the total cost remains same and your observation1 is true but then we may have intersection between two regions and observation2 is not valid (I think we need to prove your observations in some other way ).

Also you didn't use any of those observations in your code for div1D , main point was that we could divide horizantally or vertically a given submatrix , can you prove why this strategy gives optimal solution ?

`otherwise we can merge them into a bigger square.`

ohk i understand it now(skipped that part :p).

can you prove the main part, why dividing horizantally/vertically while transferring is optimal.

`An optimal solution exists such that no two painting regions intersect`

Therefore it must be splittable.nice, i was trying to draw some counter example's but seem's i can't avoid both a horizantal cut & vertical cut simultaneously (except the whole rectangle ) inside a rectangle , such a strong statement.

This conclusion is wrong, consider the following painting regions on a $$$9 \times 9$$$ board:

$$$\text{1 3 3 5}\\ \text{3 7 5 9}\\ \text{7 5 9 7}\\ \text{5 1 7 3}$$$

What you actually need is that if the optimal solution is not splittable, then the projections of the regions onto the longer side cover the longer side, so the cost is at least its length, which is easily achievable (just take the whole grid as a painting region).

$$$f[x1][y1][x2][y2]$$$ denotes... Well, you know.

When it is all white, it is $$$0$$$.

$$$f[x1][y1][x2][y2]=\min(f[x1][y1][x2][i]+f[x1][i+1][x2][y2])$$$ (Split it vertically)

(Split it horizonally too)

And paint a square with length $$$\min(x2-x1+1,y2-y1+1)$$$, then split it to two smaller rectangles.

It is $$$O(n^5)$$$ with small constant.

What does "... Well, you know" mean?

The minimum cost to paint the rectangle with left lower corner $$$(x1,y1)$$$ and right upper corner $$$(x2,y2)$$$ to all white.

I think it should be

max(x2-x1+1, y2-y1+1).Well, actually my solution is a little different to other solutions (including official solution). You mean using a square with length $$$\max(x2-x1+1,y2-y1+1)$$$ to paint all the rectangle white, while I mean using a square with length $$$\min(x2-x1+1,y2-y1+1)$$$ to paint only a part of the rectangle.

The following picture describes my idea.

got AC with n^6 dp (code). Can someone hack my solution?

how to solve div2 C?

You can have at most

`2^k`

distinct elements, where`k`

is`(8 * I / n)`

.If there are

`m`

distinct elements in the sound file, you need to reduce`d = m - 2^k`

elements to fit onto the disk.Let

`cnts`

be an array that:`index: nth small element`

`value: how many times it appears`

(We can use std::map to obtain such an array: counting with std::map, iterate over the map, collect its value part.)

For

`i`

in`[0..d]`

, we change all the smallest`i`

elements and the largest`d - i`

elements, count how many element we changed, and the final answer is the smallest count. (That is,`sum(cnts[1..i]) + sum(cnts[(m-(d-i)+1)..m])`

) (We can use prefix sum array to calculate the sum)you don't even need to use map to count, you can sort them and count number of elements each value. my_code

I think two pointers is enough :P

A is the hardest problem among ABCDE :(

DSDSDASDSDDDS I CAN'T AGREE MORE.

I wasted 40 minutes in total on A, misread it like two times and had some horrible bugs. On the contrary, I saw the ideas for B-E immediately.

Got hacked on A :(

maybe it's the hardest among ABCDEF :(

My F failed, so I can't say that :( But it seems so.

The task is natural and simple but the instruction is not written "smoothly", so hard to understand.

B is totally dump.

Maybe I will never write Um_nik contest anymore.

Now I am upset enough to give some bad words, but I just can't.

The last time: B is dump.

Here you are..

B is actually frustrated because they didn't explain the test cases properly

not only I experienced this

B was grade 3 maths, I think it should be tagged with math* instead of geometry* and given 500 rating.

Maybe it's not the problem but it's you.

Wow, another implementationforces round, so cool (no)(2).

In Div1E if the grid was small enough, I believe it could be solved by bipartite matching(with the observation that it is always worth to choose an entire line or column). Is there a way to "normalize" the big bipartite graph and transform the task into flow problem or something similar?

You can compress the coordinates to get a grid that is essentially 100 by 100. The observation is that only the boundaries of the rectangles matter.

Div1C and Div1E are so super standard, especially E

how to solve div2 c??

First you can note that the position of numbers doesn't matter. So think of a set of numbers (multiset) instead of array. It's because when we select $$$[l, r]$$$ it will "influence" all numbers.

So now we have to make all numbers in our set in range $$$[l, r]$$$. It means that when we select some $$$[l , r]$$$ all numbers that are

outsidethis range will change.So our answer for selected $$$[l, r]$$$ is $$$ans = cnt[1] + cnt[2] + ... + cnt[l-1] + cnt[r+1] + cnt[r+2] ...$$$, where $$$cnt[i]$$$ count of number $$$i$$$

Now let's think what we have to do in our problem :D

$$$ourTotalMemoryUsed = n*ceil(log2(K))$$$, where $$$K$$$ — number of distinct elements

$$$maxMemory = 8*I$$$

$$$overallMemoryUsed \le maxMemory$$$ (overall memory should be less equal then max memory)

$$$n*ceil(log2(needK)) \le 8*I$$$

$$$ceil(log2(needK)) \le 8*I/n$$$

$$$needK \le 2^{(8*I/n)}$$$

That means that our result set should have less or equal then $$$2^{8*I/n}$$$ distinct elements.

Now let's select some $$$l$$$. Now we have to select such maximum $$$r$$$ that number of distinct elements in that range will be less or equal then $$$needK$$$ and our answer for selected $$$[l, r]$$$ will be $$$n - (r - l + 1)$$$

Why? Because elements

outsidethis range will change.Now how can we calculate it? Iterate through all elements in our

sortedarray. It will be our $$$l$$$. Then using 2 pointers we can find max $$$r$$$, that number of distinct in range $$$[l,r]$$$ will be less or equal then $$$needK$$$Could you take a look into my solution, it is what you said but do not pass 10th test :(

https://codeforces.com/contest/1199/submission/58049925

Increase

`R`

before entering your`for`

loop.Otherwise you add

`cnt[b[R]]`

twice. Once in`while`

, next time in`for`

loop.aijey can you please tell me why the position of element doesn't matter ?

Any range you select, you should check all elements, whether they are in range, and change them if not.

Example: 2 4 1 5 2 3 5. [3, 4]

Checking a[1] = 2 -> changing...

Checking a[2] = 4 -> in range(don't change)

Checking a[3] = 1 -> changing...

Checking a[4] = 5 -> changing...

Checking a[5] = 2 -> changing...

Checking a[6] = 3 -> in range

Checking a[7] = 5 -> changing...

So ans = 4. You can see, that any way you shuffle the array, the answer for [3,4] will be always 5

UPD:a[5] isn't in rangeBut can you please tell me why a[5] = 2 is in range . By the way thanks actually I misinterpreted the question .

Oh, it's not. Sorry)

What was hacking test for Div2 C/Div1 A ?

maybe 2^(I*8/n) is too big to exceed the range of int.

(sorry, I made a mistake

$$$I\le 10^8$$$...

I use 1<<((I * 8)/n) and get FST QwQ...this may be what memset0 means.

Yes, thanks.

I wrote

I=min(31,I),I=1<<Iand I was hacked.Because 1<<31=-2147483648When can I resubmit? I have almost solve. I want test my new code.

After system testing

Messed up problem A itself. Can somebody explain the logic now?

Iterate for whole array :

Run two loops :

for(int j=i-x;j<i && j>=0;j++)

for(int j=i+1;j<=i+y && j<n;j++)

if in any of them a[j]<a[i] than index i wont be answer else that index is answer and return that index.

How to solve Div2-C?

From disk size and number of samples you calculate the available bits per sample. This determines the biggest difference from lowest to highest possible storagable value.

Then you find among the input samples the biggest possible count of samples with a difference less than or equal to the above value.

The problem statement is easy to misread. The number of bits needed is calculated based on the number of distinct values, not the range of the values. So you need to find the optimal range to clamp the values such that the number of distinct values after the clamp is small enough.

Can someone please explain an online solution for DIV2-D?

mango_lassi can u please share your approach?

What I tried to do was sort all people on the basis of the last change of type 1, with that change.Start iteration from last 2nd type change, and maintain 2 pointers, 1 on people array(sorted by last change), and other on the array holding 2nd type of events, maintain a maximum variable and update the final value of in-range people with maximum of (current value of that person, largest of x till now) and decrease pointers, continue....

Edit:: Sorry didn't read "online" in your comment.

build a lazy propagation segment tree where the lazy values represent the value x in type 2 updates.

A type 1 update would need to push down the lazy values from the root to the leaf, and then update the array value at the leaf. A type 2 update just sets the lazy value at the root. To push a lazy value of a node to its children, you update the lazy value of the children to the maximum of the node's lazy value and the child's lazy value, then set the node's lazy value to some garbage value which is at most 0.

When querying for the value of one point, we push down the lazy values from the root to the leaf, and max the array value with the lazy value at the leaf.

How's that even possible that O(n(x+y)) solution does not pass A? 58001554

It's (s — x) in the 2nd loop i think, buddy! :D

Oh god :(

You wrote in line

$$$ for $$$ $$$($$$ $$$int$$$ $$$j$$$ $$$=$$$ $$$s$$$ $$$-$$$ $$$1$$$; $$$j$$$ $$$>=$$$ $$$j$$$ $$$-$$$ $$$x$$$ && $$$j$$$ $$$>=$$$ $$$0$$$ $$$;$$$ $$$--j)$$$ j >= j — x instead s — x

I think its the error

Any ideas why it's TLE xd? 58001816

Maybe its because array V is not global

I think passing an argument to a function shouldn't affect complexity

If you send data without reference to function, the function will copy the value first. So complexity of each checking is $$$O(n)$$$. Sending reference as vector& and you will get AC. I think.

Thanks bro

For Div. 2 D, anybody has ideas about what is the 4th test case? Please share it :D

Btw, F can't be solved in polynomial time for big integers.

HintReduce to hypergraph 2-coloring.

If Um_nik in panel AND you use Java, Run Virtual Contest at same time.

Div. 2 C is a bad problem

Pretests are bad too. Nearly 1/3 fst.

@Um_nik: Out of curiosity, question about F: If there is no prime that divides at least n-2 numbers, is it true that if there exists a solution then solution trying out completely random assignments will find one?

I don't know, tests were prepared by Burunduk1

for me it's not obvious, what "random assignments" are

i tried out "random shuffle + greedy assignments", on my tests it finds answer during first 100 tries.

I meant simplest possible way, no greedy or whatever, just i-th number belongs to first group with prob 1/2 (all events independent)

Wow =) i even could not imagine so simple solution.

It gets WA 46 with cutting by TL=0.5 seconds

But does this test satisfy the assumption that no prime divides at least n-2 numbers? Because my solution that got accepted in contest 1) does some weird mumbo-jumbo, 2) tries some random assignments satisfying some.constraints determined by first part. However if there is no prime dividing >=n-2 numbers then my first part does nothing and second part is trying simplest possible random assignments as I described (and it got accepted as I said). It seemed fine to me as 3-edges are far less limiting than 2-edges and I still can't have a lot of them, but I didn't have any formal proof and was curious whether I am right.

Hm... No. Moreover, it seems, none of tests, where random assignments fails, satisfies the assumption.

You may investigate tests more precisely

How to apply Segment tree in problem D?

https://codeforces.com/blog/entry/68775?#comment-531334

hackforces!

Why the pretest is not strong?

Div.2 C can be solved using binary search.

Yes! Here is my code : https://codeforces.com/contest/1199/submission/58018073 Techniques used : Sorting,Prefix Sums, Binary Search. Feel free to ask the doubts !

https://codeforces.com/contest/1199/submission/58043340

my solution is giving wrong answer on test 13 can u tell where i am wrrong

Could you please explain the work of this line of your code ? ans = min(ans,pre[i-m]+suf[i+1]);

pre[x-1] is used to get the number of terms which are less than the term at x and suf[x+1] is used to get the number of terms which are more than x. Basically, I am calculating the number of element which are not in range [l:r] in constant time.

Find the bug in code. Spoiler in edit history :(

You might fool systests but you can't fool me.

Hacked :)

Can someone explain me how to use segment tree in problem D(div 2) please

you don't need segment tree

just read the events form end to start and try to solve it

Thanks.I know this solution, but we can solve it

onlineusing segment tree.https://codeforces.com/blog/entry/68775?#comment-531334

also, "solve" instead of "solute"

Thank you

use a lazy propagation seg tree with the max operator and with two change operations

Thank you

Here's my take on it: 58038546 (it uses a lazy segment tree implementation using pointers)

Just out of curiosity, can I get a count of how many solutions failed system tests for Div2C/Div1A?

nobody:

pretests:

Somehow I didn't think $$$O(n^5)$$$ could fit the time limit for D and tried to come up with an $$$O(n^4)$$$ one. My idea is basically to only consider rectangle $$$(x_1, y_1, x_2, y_2)$$$ where $$$x_1 = 0$$$ or $$$y_1 = 0$$$. I don't know how to prove it formally though. Code

Hacked :)

Great, thanks!

can we solve C by Binary search ?

Yep! I solved it using binary search, first applying BS on the answer, which would be b/w 1 to cnt (cnt being the number of distinct numbers) and then another binary search nested in it to find the min number of changes needed to obtain that particular distinct element count. Here's a link to my solution div2C

Correct me if I am wrong,

But my Div2 D's solution passed the system test, without being right. Test Case:

input

4

1 2 3 4

2

2 1000

2 1

Output 1 2 3 4

Expected 1000 1000 1000 1000

Link to Code https://codeforces.com/contest/1199/submission/58024929

Yeah, it is incorrect, mine gives 1000 1000 1000 1000. And i was expecting the pretests to be strong, jokes on me :P.

Auto comment: topic has been updated by Um_nik (previous revision, new revision, compare).https://codeforces.com/contest/1199/submission/58037512 https://codeforces.com/contest/1199/submission/58025301 Two same solution one giving wrong answer and other being accepted.

One of the submissions was during the contest and the other was after the contest. The test case (Test 109) which the first submission failed on was added after the contest as part of uphacking, but is not used to judge submissions in the contest.

Div2C:

As they talking about bits, I thought the distinct values are continuous (that's how bits work right?) . Am I the only one who faced this confusion?

Even the question talks about the range:

I thought every number from l to r (both inclusive) are represented by one of the bits. So the distinct values are contiguous. Did anyone else feel it ambiguous?

Um_nik can you please look into this? I felt the question statement was confusing.

As it says about K distinct values, but then it says about a range [l, r]. So I thought we can represent values

[l, r](contiguous) using the 'k' bits. But it turns out that we can use 'k' bits for non-contiguous values as well.In that case why did they talk about a range [l, r] and had confused the statement?

The range is necessary for the problem statement. If you can select arbitrary values to modify then you would greedily retain the K distinct values with the most occurrences.

I thought the same thing. I should

reallyread questions more carefully next time.`If there are exactly K distinct values in the array, then we need k=⌈log2K⌉ bits to store each value.`

I was confused too. But after looking at it a second time, I think this means to compress with a dictionary.

For example, if there are 3 different values 'A', 'D', 'K', and message M ['K', 'A', 'D'].

'A' => 00

'D' => 01

'K' => 02

M => [02, 00, 01]

With a dictionary, values don't have to be continuous.

No it just means that if you had distinct values a1, a2, a3, .... an then you can describe each of them with ceil(log2n) bits.

Example: if you know that you are given values 11, 12, 15, 257 then you don't need 9 bits to hold 257. Instead of it you can mapping 11 to (00), 12 to (01), 15 to (10) and 257 to (11).

I didn't completely understand the statment too.

Is there anyone like me who didn't understand the problem statement of C?

If you already got AC,then please share your idea.

2D/1B solutionLet request time be

it's order number.Let's keep two arrays: the first one will hold our values and the second one will hold the time for the last first type request (1 p x). Let's name them

valuesandlast_upd.Iterate over the requests.

If it's first type request (1 p x), then

`values[p] = x; last_upd[p] = request_time;`

If it's second type request (2 x), then save it as pair

(request_time, x)in the arraysecond_type_requests.Right now there are the last values in the array

values, which were changed by the first type requests. Let's find out which second type request can change this value. It goes without saying that the request_time of the second type request should be more than the request_time of the first type request. If such request is not alone, we should choose the one with the biggest value.We've reduced our task to finding maximum on suffix of the array second_type_requests. We can find it fast using the

suffix_max_array.Time complexity is O(N + Q)1A is 2C

Nice explanation! Thanks!

Hi. Can anyone point out any optimization to improve my solution? https://codeforces.com/problemset/submission/1199/58040359

Fast I/O makes a huge difference. You can check my submission and see my comments marking the optimizations at the beginning. Include those lines at the beginning of all of your submissions (or use scanf/printf) and your programs should run considerably faster.

Can someone explain how to solve div1E? I realized that I need to somehow reduce the problem to flow, it is clear that you need to compress coordinate, but I'm apparently stupid and can't understand what kind of graph here you need to build.

Because the cost function is min(h, w), you can assume that all your actions are of two types only: paint whole row in white or paint whole column in white. Than we can say, that every black cell needs to be painted either from the corresponding row, either from the corresponding column. Let's create a bipartite graph. One half will be for the x coordinates, another one for the y coordinates. First lets assume that we don't compress the coordinates. We will add a single edge from ith row to jth column for each cell (i, j) which is black. Now you need to find the minimum vertex cover of this graph, because at least one of row/column needs to be painted. When you compress coordinates, every vertex will correspond to the range of columns/rows, and because of it will have a weight equal to the length of this range. Finding the minimum weighted vertex cover can be deduced to finding minimum cut of the network, where you add edges from source to each vertex of the first half and add edges from each vertex of the second half to the sink with with the capacities equal to their weights, and keep the original edges of the bipartite graph with the infinite capacities.

A similar version of this problem is "Given a $$$N \times N$$$ grid containing white and black cells. In each operation one can color all black cells in a row or a column white. Determine the minimum number of operations required to turn all black cells into white".

The solution is to construct a bipartite graph of $$$N$$$ vertices on both sides, and for each black cells $$$(r, c)$$$ we connect the $$$r$$$-th vertex on the left side to the $$$c$$$-th vertex on the right side. The minimum vertex cover of the resulting bipartite graph is the answer since each black cells is destroyed by the operation corresponding to the vertex which covers that edge.

As for Div1 E, a similar bipartite graph $$$G = (X, Y)$$$ can be constructed on the compressed coordinates. So the problem is to find the "minimum weighted vertex cover" on the graph, which is equivalent to the min-cut on the following flow graph:

See this article for detailed explanation.

Solution for Div2 D without using segment tree.

Observation:

a later higher payoff will cancel all previous lower payoffs.

a citizen's final balance is determined by the last change and the highest payoff after that.

We go through events in reverse.

Record a visited array for all citizen and the highest payoff.

On event 1 p x:

If the p-th citizen has been visited, then its balance has been changed later, pass.

else, mark it as visited, update its balance to max(highest_payoff, x)

On event 2 x:

update highest_payoff to max(highest_payoff, x)

It may be easier to understand by reading the code: 58038489

Thank you , can you please also explain how to solve C ?

I tried, but found it hard to express this algorithm in English.

https://codeforces.com/blog/entry/68775?#comment-531353

Calculating

`sum(cnts[i..(i + 2^k - 1)])`

may be more straightforward here.My submission

58042687 on Div1 C

and

58041401 on Div1 F

passed the system test.

Of course, they failed during the contest, but after I tried to do some voodoo programming, I finally managed to write some randomized sols that (I think) should not be passed, but they finally got accepted (almost TLE/WA).

-C

Nice, could you please find something for this: 58027618?

-F

An interesting thing, cf predictor says that cnnfls_csy should get 583 pts, whilst he got only 296. Why is there such a difference?

https://codeforces.com/contest/1199/submission/58043340

can someone tell me why it is giving wrong answer on test 13

Try with this small test, the right answer is 3:

The array D will be:

It says his previous rating was 1500, but that's wrong

Ok, thanks!

someone please recommend some other problems like Div2 D where we can get answer without using segment tree?

SQRT decomposition should work well

Weak pretest, random algorithm bypassed, flood of fst.

Good contest.

Is there an optional solution to solve Rectangle Painting 2 if cost is max(h, w) ?

all right

The best today.

How to solve Div2-D without using segment tree?? (I tried to understand through comments but can't)

My solution

You can ask any questions if you have.

Can someone please help me on DIV2 problem C question. Let me know if my logic is correct:

first find critical k <= min(n, 2^((8*I)/n)). Then sort the given array, and convert the array to its freq array i.e. if original array is 1, 2, 2, 3, 3, 4: change it to 1, 2, 2, 1 (each element in this new array represents the frequency of distinct elements in original array). Now original task is to

minimizethe number of changed elements, that is now equivalent to findingk-subarray with maximum sum in new array(using sliding window method in linear time), and then returnnew array size — max sumfound.Am I missing something here? It is failing on 10th test case. Link to my soln:

https://codeforces.com/contest/1199/submission/58049910

Your logic is correct, but there was a flaw in your computing the window sum. In maintaining the maximum seen so far, your code takes the max of the current window and the next one instead of updating the window sum. This could mean that sometimes you include elements more than once, and sometimes consider a group of non-contiguous elements.

I've made a slight modification (here), and marked the place where I changed code for convenience :)

Oh yes! So silly of me. Thank you so much for taking your time & debugging, and even writing down the correct code :). Much appreciated. Finally, submitted the correct code. ✌

Looking for a crazy contest :P

Hope you bitch got minus rating

why -24, I'm a subnet?!

I need editorial, please :(((((

Fuck D, E's author. Losing free point for E just because of min/max. They didn't even bold it.

Once again please. You thought that we gave two exact same problems, you can't open your eyes, and it is my fault somehow?

CRAZY GREEN HAIR BENCHODE, I GOT MINUS

Afaik, if the problems were the same but with different constraints, they would be named D1 and D2 instead of D and E. Moreover, the author always mentions it before the round whether there is a problem with 2 subtasks.