Hello, Codeforces!

On February 02, 17:35 MSK Educational Codeforces Round 37 will start.

Series of Educational Rounds continue being held as Harbour.Space University initiative! You can read the details about the cooperation between Harbour.Space University and Codeforces in the blog post.

As usual, the round will be **rated for Div. 2**. It will be held on extented ACM ICPC rules. After the end of the contest you will have one day to hack any solution you want. You will have access to copy any solution and test it locally. You will be given **7 problems** and **2 hours** to solve them.

The problems were prepared by Mikhail PikMike Piklyaev, Vladimir Vovuh Petrov, Adilbek adedalic Dalabaev and me. One of the problems was proposed by unbelievable02.

Good luck to all participants!

I also have a message from our partners, Harbour.Space University:

We are happy to announce the addition of two new coaches to our Hello India x Russia Programming Bootcamp: Gleb GlebsHP Evstropov, Artem VArtem Vasilyev and Filipp DPR-pavlin Rukhovich will all be attending at our India location, Amrita School of Engineering.

We look forward to seeing you all there this spring! For those of you who haven't registered, there's still time.

The Early Bird discount will be set at 20% for those who register before **February 12th, 2018**.

If you have any questions we can help you with, please connect with us:

Phone number: +34 674 291 422 Email Address: hello@harbour.space

UPD. Editorial is here.

:)

Hello every gays! Please say**"China No.1"**, or I will kill you by my assist in the PBUG!

:)))))))))))))))

I like BledDest's contests.

please make sure that the contest is rated for div-2 , sometimes it becomes unrated for some statement/data system faults , please check them again

3rd rated in this week <3

Sadly, it coincides with Hackerrank's HourRank 26 :(

Hackerrank's HourRank 26 coincides with this round(there is a difference)

Well Hackerrank scheduled Hourrank 26 a month ago.

Once upon a time, educational rounds used to be unrated.

guess who forgot to thank Mike

Is it rated?Are u retarded??

It doesn't take L to figure out that he is indeed retarded lol.

Of course. It is rated for div.2.

System Tester halyavin haven't registered yet.:)

He has :) Already 100+ hacks

halyavin has 187 successful hacks and 15 unsuccessful hacks, and he has solved all problems in this contest.

clash with HourRank on HackerRank .

Woooow!!!

VK Cub 2018... VK Cub 2018 everywhere

I hope they add contests between Feb 7 and March 10 lol. One month is too long a wait for a contest.

Got a bit more contests than I expected :P. Love CF <3

Wow shit! VK Cup 2018 Wild_card round 2 has length is a week.

There are so many contests. I like VK Cup very much, but they are too late for me(23:35,UTC+8).

Since CF made Educational round rated ,"That 24 hour long waiting for standings and staying at your toes" makes it so exhausting to participate in a round :'( .

Anyway that's the beauty :D .

Hello Codeforces, how can I suggest new challenges for Educational Round !!!

It will be the best Educational Round!!! Because, in list of authors have unbelievable02!!!

;)

ты кто ?

Superman

নিরাপদ সড়ক চাই

:O

What?

The contest will be rated for me if I only do hacking?

I thought you couldn't hack without lock (and submit)? Has something changed?

In Educational, after that 2 hours for solving, hacks are open for 24 hours. What I was asking was if I register but not solving anything and just do some hacks in that 24 hours period, will my rating be modified.

NO, the hacks in educational don't give any rating and don't affect on your final result.

Your rank gets modified indirectly... If you hack a person who is ranked above you, your rank decreases. So the more hacks the better.

No, hacks gives nothing

No. If you didn't register, it isn't rated for you.

I wish, This time I will get "

Plus Rating" by solving 3 problems.wow more than 7200 registration..:)

wish you high rating~

F is very similar to gss4 on spoj.

how to calculate D[x] = ? quickly

hmmm, spent lot of time on it, tnx

u can precalc for all x in range 1 <= 1e6 with eratosthenes sieve (nlogn)

the problem with me is the time I take to calculate the divisors .

halyavin Please hack my A,B,C.

LOL, solved F but cant solve C XD

how did you solve F ? I tried to use Segment tree but couldn't update or get divisors in short time .

D(x) decreases very fast. And if x <= 2 we can dont update this position. So i have 2 segment trees and precalced all d[x] in NLoG :

for(i=1;i<MAX;i++) for(j=i;j<MAX;j+=i) dp[j]++;

yes but how to update a range using different values . I don't think lazy propagation can work .

In this problem you can use set instead of range update. It will be very fast because d(x) decreases fast too

thanks a lot .

Lazy propagation can be applied by keeping track of the number of time you want to apply D(ai) operation on the range. For each range [l : r] store the numbers who have values > 2 because D(2) = 2 & D(1) = 1 and it's redundant to apply update operation on these 2 numbers. so when you are updating the range of numbers, pass the value of Lazy[range] as argument so that you can apply D(ai) operation on numbers > 2 in the range Lazy[range] of times and then return the updated numbers in the range. i hope this helps.

got it .

thanks a lot .

Thanks for this I got this observation but couldn't apply :(

I understand that this solution will run fast enough, but how to analyze its running time complexity?

I think that x has max log3(x) dividers, so complexity is about qloglog3(max(ai))

,

O(k^{1 / 3}) in practice. Then we perform at most operations per index, resulting , is that it?Yes, you are right

Actually, the

O(k^{1 / 3}) factor should be replaced by the maximum number of times you can makea_{i}<---d(a_{i}) beforea_{i}becomes 1 or 2. Fora_{i}≤ 10^{6}, this number is around 4.wow lot of coder cant solve F,

So, what's the testcase 18 in problem D???

is the idea for G to use inclusion exclusion for each query observing fact that there will be atmost 8 distinct prime factors.

Or any better??

I did the same thing. I think that is the intended solution.

problem E : 190E - Контрнаступление

I was wondered how to solve problem E... thanks!

In problem F what is maximum number of updates on ith index till value of a[i] becomes equal to 2,if not initially equal to 1.

6

8

Spend an hour in Question B, wrongly understood the question.

I Got WA just because of an initialization. Really feels bad :(

Idea for E ?

My idea is, first form a graph with the non edges. Insert every element from 1 to n into the set. For every element from 1 to n if it is in the set perform the dfs. DFS: In dfs we take a vertex and then iterate through all the remaining elements in the set and check if there is no edge between this vertex and the vertex in the set. if yes, continue. else delete this vertex from the set. Now keep track of all the elements you deleted from the set. Main: Now for every element you pushed into the vector or deleted, perform the dfs. Now this is one connected component. Now repeat the procedure for the remaining elements. Here is the solution https://ide.geeksforgeeks.org/0JuIOaiKWO But i dont know if it is correct.

i tried to do same thing as you told.can you please check my code 34866232 ?

What i think is 1: You are not erasing from the set. So it will be O(n2); You need to erase in the dfs. And actually it is not dfs. I gave name as dfs cuz i din think of any other name. You are doing it by brute force. As you are calling for each vertex. Just check my code https://ide.geeksforgeeks.org/0JuIOaiKWO.

2: You are using map. it has O(logn) while vector has O(1).

i) n < 2000 Just solve using BFS/DFS

ii) n >= 2000 We can easily know that there is a largest connected component and small size connected components if n >= 2000.(Since eliminated edge is smaller than 200000)

except largest connected component, let size of connected components = k Then (n-k)*k edge must eliminated to make that cc becomes alone. Since n >= 2000, k is smaller than 150.

So first we think set of all vertex which has more than n-150 eliminated edges. Then that set's size is smaller than 150.(roughly)

BFS/DFS on that set.

It is my idea but i cannot sure it is right. Because I'm failed to implement.

Assuming node

Xhas anti-edge with {u_{1},u_{2}, ...,u_{k}}. Then, there are two thing we need to handle:Union X with

u_{1},u_{2}, ...,u_{k}.Union every node inside each of the following segment: [0,

u_{1}- 1], [u_{1}+ 1,u_{2}- 1], ..., [u_{k}+ 1, $n$].Which is reduced to this problem from VK Cup 2015 Final.

Can you elaborate a bit more?

This problem is the same with E today. Editorial can be found here

If the component graph is not connected , then the original graph is connected => number of connected component is 1. else , start bfs in the complement graph in a different manner , start from a vertex push in the queue all the unreached vertices and continue like this and for each node we use DSU to count number of sets which in result is the number of connected components.

can someone plz tell me why this solution doesnt work ? https://ide.geeksforgeeks.org/eN7gAAmHB0

I gave this solution just 5 min after the contest. but it got rejected on test 4. Althouh i solved using queue and bfs after 15 min, i still cant find what is wrong with this.

34860361

sorry for my mistake :(

Sum of all n of all the test cases is <=1000

Damn the feeling when you get A and E but not B and C due to overthinking >:(

Shit! "cnt x y" I thought that we get water from y then pour to x :(

Will unsuccessful hack result in decrease in points ?

No.

I know that to solve problem F,we are able to use segment tree and I can't solve this problem.I need someone help me to solve it.Need we use some skill?

check any accepted code.

I need some idea for getting or updating

Oh shit!If we save max of the segment,we are able to solve 920F - SUM и REPLACE by removing case that max<=2

My solution: build 2 segment trees, one to maintain the sum of elements in segments of array a, one to maintain the count of

floor numbersin segments of array a.Here, let's say that

floor numbersare numbers which D(x) = x. (People say only 1 and 2 satisfied that rule, but I'm not so certain about that, so, just check the criterium manually — it won't cost much actually ;) ).You can do both REPLACE and SUM queries without lazy propagation — simply traverse throughout the trees. However, to avoid TLEs, you can skip traversing if all elements in a segment are

floor numbers.For example, if a segment is from the 3rd to 6th element, and the

floor numberscount is 4, you can skip the following traverse (since these numbers can't be replaced by any distinct integers anyway). If you're working on a REPLACE query, simply ignore it and break, otherwise, add the sum of elements in the segment represented by the node, then break the current traverse.Or you can notice that each element will be processed no more than times and do type one operations explicitly.

I'm not sure if I get what you meant, can you clarify more?

I knew the maximum processes possible for an element, this is why I said I don't need lazy propagation for my segment trees, just traversing with worst complexity O(segment_length) (but the average complexity is whole lot lower thanks to the notice of no-longer-processed-elements in a segment).

I see that it said Accepted rather than Pretests Passed for this contest. So does that mean there are no Systests? Not quite sure as its my first Educational Round.

For educational rounds system tests will be run which include the hacks as well.

the very tough contest... unclarity with the statement

Submitting a problem was harder than solving it!!

Please repair the server

P.S.posting this comment as wellSubmitting a problem was harder than solving it!!

Please repair the server

P.S.posting this comment as wellin E can there be ever more than 100000 components?

I think for that you have to provide something like 100000*(100000-1)/2 forbidden edges.

I actually overlooked the constraints.

If there can be more than that components then there is a free hack for You.

submission link

I did an overkill for C, which resulted wrong as well.

Can someone point out the mistake : CODE

Logic : I build an index array for input, and stored the indices with 0 in a vector. I traversed the array and if I found an element with lower index than a smaller element, I checked if there's a zero between them.

Ex : 1 3 4 5 6 2

Here, 5 has 2 (smaller element) with greater index, so I checked if there's a 0 (unswapable element) between them

Submitting a problem was harder than solving it!!

Please repair the server

P.S.posting this comment as wellI had no problems. Maybe some latency issues on your side. Check by pinging.

E and F are copied. Make the round UNRATED.

Where they were copied from?

problem E http://codeforces.com/contest/190/problem/E

Why do div1 users have predicted rating on cf rating predictor? Will this mess up the prediction?

Which predictor are you using ?

http://codeforces.com/blog/entry/50411

Welcome to the club

That moment when you have the idea to solve F (failed during contest, but finally got it AC-ed after), and you completely have no ideas in D and E...

Well, with the insanely poor performance in 3 first problems, goodbye rating (again)...

Any idea why this is not working ? https://cf-predictor-frontend.herokuapp.com/contestSelector.jsp

It was working the previous educational round even during the hacking phase.

Check here. https://cf-predictor-frontend.herokuapp.com/roundResults.jsp?contestId=920

This seems to include Div 1 as well. Won't that affect Div 2 rating changes ?

I guess the exact rating would be a little bit different from the predicted ones.

Are Div 1 and Div 2 rating changes completely independent of each other ?

I am not the developer of this predictor, so I don't know how the ratings are getting calculated behind the scenes.

That moment when you finish solving E 30 seconds after contest ended :))

Try to hack me, please.

This is my submissions page. :)

Why is this invalid input for B? I don't see any constraint that is not fulfilled

edit:

`Validator 'validator.exe' returns exit code 3 [FAIL Integer parameter [name=l_1] equals to 5000, violates the range [1, 2000] (stdin)]`

why 2000???

Sorry, we will fix it in 10-15 minutes.

halyavin is coming !

System testing will be done by halyavin

System Tester — halyavin is on fire !

can someone explain the Idea of

D, Please?given that if you sum all the tanks water in one tank, then you can take whatever you want water in amount multiple of k. now, the problem is to bring the (V%k) amount. make a knapsack from all the tanks on an array of all values under K. The cruel idea is that you maybe need to module over k when you are summing tanks values in knapsack process.

I have a silly (post-contest) solution for problem E.

First of all, it is mathematically provable that if G is non-connected OR if

`diam(G) >= 3`

, then !G is connected (where !G is the complement of G). So if any of the above hold for !G we draw the conclusion that G is connected. We quickly eliminate these cases.Now we are left with only cases in which !G is a connected graph with

`diam(!G) <= 2`

. If we analyze it, we can draw the conclusion that the original G isalmostconnected (i.e. it has one very big connected component). We want to brute-force the answer for the original G, but we can't do that yet (it might have a large number of edges). We choose some number (`O(M)`

) of random edges from G and brute-force on this partial graph. We remove all nodes in the largest component and all nodes adjacent to nodes in the largest component (we remember the size of this component). Finally, build the sub-graph of the original G which has only the remaining nodes. Brute force on this sub-graph and output the answer + the size of the big component we discovered before.This is the submission: 34873106

It seems like this always give the correct answer and the run-time shouldn't be too high provided that we discover a large enough part of the big component during the brute-force on the partial graph. I'm curious if the idea is hackable.

It seems to work (get AC) without the initial elimination (I guess the condition that one very big component exists holds anyway for larger graphs), but it might be easier to hack with RNG prediction. Maybe.

Will a successful hack be considered valid for me in any of these cases ?

last educational contest i was hacked by

Ka8eeMwho didn't participate in the contest but he solved the Problem A before hacking my solution.Yes, I am sure about the latter one.

Editorial?

It will be posted after the hacking phase and the system testing are over

This is correct solution for Problem B. But when I use sort function, it gives me wrong answer on Test 5. I am not able to figure out the reason. Please Explain.. (http://codeforces.com/contest/920/submission/34874806)

The problem in your sort function is that it compares the data only based on the L values, that fails in case of two students with the same L.

But my 4 test passed in which same value of L exist. The sort function manage the same order if Both L are equal. Still Not get it.

I'm not sure how exactly it works, but I submitted your solution after changing the sort function and got AC.

Ok Thanks for helping :)

`The sort function manage the same order if Both L are equal.`

Not necessarily. See

`stable_sort`

Thanks!

How to solve E?

Read this

search for the node with adjacent nodes fewer than sqrt(n). let it x. there must be at least one , or the overall graph is small. Now, connect all the nodes (which are not disconnected with x) with x. Now, you have a component that has more than or equal (n-sqrt(n)) nodes. brute force on the rest nodes.

using brute force.Now there are (n-1)*n/2-m edges.If n less than 200,it's easy to solve,or we can prove that connected components never exceed 200.so we can sort the edges in order.And using union-find set to merge connected components.This is my submission 34858691.

There is a simple way like this: You use set A to store vetices, set B to store pair of vertices which is not edge. Then we will do dfs, for every vertex u, push all v which are in set A and pair <min(u, v), max(u, v)> doesn't in set B into a vector. Of course all vertices in the vector are adjacent with u. Then you erase all of vertices in vector from A and start dfs from each of them. Complexity: log n for std::set, n for visiting n vertices -> o(n log n)

Sorry there was a mistake. My solution was accepted so i though it's complexity was o(nlogn). It was o(n^2 logn) for the worst case (for every vertex, we check all the vertices remain in the set, so it should be n^2), but somehow passed pretest (maybe because of the constraint).

No it's not. :)

Each time, you time you meet a vertex, you either erase from the set ( cost 1), or you don't.

Notice that you don't only if it belongs to the given E given edges, so you have at most O(E) pairs, and their cost is O(E).

Totally complexity is linear in number of edges and nodes multiplied by a log factor.

In CF Educational R 37 in Problem C, I had written the following code, where I have done cumulative sum of 1's and checked if all bits in the string between i and arr[i]-1 are 1 (& if arr[i] < i, then between arr[i] & i-1).

It is failing for Case #5 and the test case is of length 200,000 !

I have spent close to 5 hours to figure out why it is failing :P. It will be really helpful if someone can help me figure this out (maybe provide a simple test case !)

http://codeforces.com/contest/920/submission/34883063

## include

## include

## include

## include

using namespace std;

int main(){ int n; cin>>n; vector arr(n); for(int i=0;i<n;++i){ cin>>arr[i]; --arr[i]; }

return 0; }

5 5 4 3 2 1 1111

Answer — "Yes"

sigh..sorry i was wrong

Yes. All n numbers should be between 1 and n and must be unique....

Also, I have tried all permutations of numbers till 10! and all 2^10-1 bits combinations for these and compared the result of my incorrect program with a correct program but could not find any test case that would produce a different results. (The program took 30 mins to run)

check this input

5

2 1 4 3 5

1010

output should be YES

but your solution produces NO

Apparently, my incorrect program produced "YES" for this test case.... This would be due to memory overflow and non-handling of zero values.... as pointed out by halyavin....

Thanks for helping out !

Yeah, I also missed it.

The input is correct, but my program also produces the correct output "Yes"

Why my test does not meet these conditions?

So what happens if

`val == 0`

or`i == 0`

?halyavin — YOU ARE JUST AWESOME! and thanks to Sokurov329 & supervillain !

Zero handling is what I was missing & just did not realize this... and spent close to 7 hours on all sorts of other things....

Really thanks for identifying this!

Next time, I will post here earlier!

i was about to commit the same mistake ! but i thought about such case

here's my solution

Could anyone provide any small but tricky test case for problem F? I am having trouble understanding the bug with my logic/implementation ( submission link: 34884739 ) and all test cases except #1 seems to be intractable.

Use stresstest for find bug.

Can someone explain the DSU solution for E, in details? An example would be really nice. Thanks.

Looks like it is legal to transfer water from tank to itself in problem D. Is that supposed to be allowed?

The output format doesn't forbid that.

Unfortunately, the word "other" wasn't supposed to be in the statement.

So , this will affect the Round ?

Could anyone please help me why i'm getting WA on problem F ? Here is my submission 34886833

Could someone explain why am getting TLE on E with

O(m·log(n)) algorithm?Here is my code 34891034 and here is explanation of algorithm and proof of complexity:So I will use set to save nodes that are adjacent to current node,and not marked yet.Note that with BFS I only need one set ,every time node is visited I delete it from set,and when it's turn to traverse adjacent nodes for nodeAwe will delete all nodes that aren't adjacent with A and after that we will add them back.Proof of complexity:Deleting and adding nodes that aren't adjacent to current node will take at mostO(m*log(n)) time where constant factor is 4 because we will add and erase those nodes.Note that we will iterate exactly once for every node in set possible so that part is linear.So maximal number of operations is 4 *m*log(n) +n< 15 * 10^{5}.What I got wrong?I see that there is a few people on the top 50 got their solution hacked, but the leaderboard still show that their solution is accepted.. is there something wrong?

Few hours ago halyavin did 190 hacks.

Now it shows 187 :/

Also, why is eddy1021's rank shown as 1(3) in common standings?

Is there any issue?

Why the rates haven't been updated? :(

because it's an educational round which is open for hacking for 24 hours

To those who solved E.Connected Components, how do we use DSU??

Right now maybe Codeforces is having some issues. It's very slow, I can't submit my solution and (maybe) the leaderboard in Educational Codeforces Round 37 is showing the results of about 10 hours ago.

Indeed, the server is very slow.

And now we have Internal Server Errors on the hack and submission pages.

Is there no penalty for wrong submissions in this contest ?

In statement of problem 920E - Связные компоненты? it is said "denoting that there is no edge between x and y. Each pair is listed at most once; (x, y) and (y, x) are considered the same (so they are never listed in the same test)". But in test 85 we can found edges 1 2 and 2 1 in one test. Why?

Problem E is not new : http://codeforces.com/contest/190/problem/E Also in the statement they say that "Each pair is listed at most once" but in test 85 they are not ! This round should be unrated!

oh i see you're in edge of falling back to cyan. (and didn't solve E though ). I think the problem E should be rejudged not unrated.

I think they should rejudge E regardless.

## SUPPORT . Rejudge E

did you read the problem "Counter attack" ? They are the same !

Well, did you ever try just solving problems instead of trying to google them during the contest? :D

Come on! if a problem is copied from another, does this not affect the rating?

You're partially right, ya. But this claim is correct only presuming many people have seen this problem beforehand.

It would be kinda tough to persuade me that all div2 participants remember the problem that took part ~350 rounds ago :D

Its an educational, its literally written in the description that problem might look similar to some in the past..

p.side.note: this drafts button needs to be placed somewhere else.

I'am against that for a rated contest the problems could look similar to some in the past.

Agree with you. Rejudge the problem E and not unrated.

Now he solved E ;)

the 85th test case of E is wrong. 7 20 4 6 6 7 4 5 1 2 2 4 1 7 3 5 2 1 6 2 6 1 7 3 3 2 3 6 3 1 3 4 2 5 1 6 7 4 6 3 7 5

(6,3) and (3,6),(6,1) and (1,6),(1,2) and (2,1) are all listed but (x, y) and (y, x) are considered the same (so they are never listed in the same test). will rejudge?

Repeated later.

Here, in the latest hack for problem E, the verdict to this hack had to be "invalid input" instead of processing it.

And since this is the last test, it's pretty easy to accepte all the solutions which failed on this test and not make it unrated.

Unfortunately, test 85 in problem E was invalid.

I don't have any permission to rejudge the whole problem, so I tried to find all solutions that failed on this test and rejudge them manually. If your solution still fails on test 85, please tell me so I can rejudge it.

Filter the status page by setting the problem section to that problem, and the verdict to "WA", and the test to ">= 84", it may help.

I did exactly this, but maybe I missed something?

True.

And I am wondering, was that hack state the only one which was processed instead of telling that it had "invalid input"?

If there are other ones it will be harder to rejudge manually.

Is it efficient to rejudge only the hack states that successfully passed? so it will detect the wrong tests.

Sorry, repeated.True.

And I am wondering, was that hack state the only one which was processed instead of telling that it had "invalid input"?

If there are other ones it will be harder to rejudge manually.

Is it efficient to rejudge only the hack states that successfully passed? so it will detect the wrong tests.

When will the system tests start?

It is over already.

When will halyavin finish testing us?

Why the FUCK are the ratings not updated still??

I could have asked politely but the system testing has been over for over 4 MOTHERFUCKING HOURS and i am going FUCKING CRAZY !!!!

You didn't even participate in the contest..

Asking for a friend.

Ok. I feel the same..

Maybe you should get another hobby T-T

E — Connected Components?is it possible to use dfs instead of bfs here ? Solution Accepted

if possible then why i get WA when I use dfs here in the following code WA using dfs

shortly my idea: i insert all node from 1 to n in a set/vector then remove it one by one when they are visited by using dfs/bfs.

I think the data of problem E in Test#85 is wrong. In the description of problem E, you said " Each pair is listed at most once; (x, y) and (y, x) are considered the same (so they are never listed in the same test). ", but it seems both (3, 6) and (6, 3) are in Test#85.

For problem E, My Submission I am getting Time Limit exceeded. Can anyone please help me where I am going wrong?

wrong thread i am sorry ):