Hello Codeforces!

On September 21, 18:05 MSK Educational Codeforces Round 29 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.

The round will be **unrated** for all users and 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, Mikhail MikeMirzayanov Mirzayanov, Vladimir 0n25 Petrov and me.

Good luck to all participants!

For a joke, How to solve the terrible problem A?

As what I said, HOW TO SOLVE THE TERRIBLE PROBLEM B??

My idea is: priority_queue make all the value of (abs(w[a]-w[b]) (1<=a,b<=2*n,a!=b)) into the queue, and choose the national w[a] — w[b], then the (n-1) pair of (w[a] — w[b])'s sum is my answer

Is'it something wrong with my idea? I need all of your help,thanks!

You have n*(n-1)/2 ways to pick single guys. So for every combination calculate new value and take the minimum.

Get it now, thanks！

But why to pick single guys first? we can calculate first n-1 minimum absolute differences and then the rest two guys will automatically suitable for single kayask

There is open-hacking for 24 hours, please don't discuss problems before this phase ends.

i think we should discuss the problems because we can get more ideas for hacks. It is not rated anyways,so i don't see any problems

The idea is wrong.because the value “a” or “b” will be chosen more than once. However,a man only belongs to one ship. In fact,we should try to pick two people out and do not consider them. Now we have 2n-2 people.we sort the array by weight. After sorting .the answer is the sum of whose index is even plus the sum of whose index is odd.

But i marked both whose diff is minimum...but still showing error...?? as shown: (a[i]-a[j],{i,j})

if(!(vis[i] || vis[j]) ans+=a[i]-a[j]

Your text to link here...

Maybe you should try to think about this example. N = 3 1 5 6 20 1000 2000 And ans should be 18

Your output is 20?

Got it...

TvT...I should first choose two single.And choose double two by two, Igot it now, thank you!

uwi be like :

If uwi is in hacking mode, we will not need system testing after the round.

How to add photo in comment section ? I clicked PICTURE (ctrl+p) but they want URL . How can i make an url for any kind of picture from my desktop ?

Another ROUND!!!!where u can relax about Rating.The more u dont want to care about ratings the more u start to care....Why rating is so cruel!!!!!!!!!!!

Is it rated?

No, the Educational Codeforces Round is based on ACM rules, so it is unrated.

Pardon me, but how do those two go together?

All the rated rounds are based on Codeforces rules, so if the round isn't based on Codeforces rules, it's often unrated.(Maybe I was wrong,it is unrated just because it's an Educational round).

This question is for uwi and halyavin.

Just out of curiosity, hacking solutions is a way to learn something new or you guys just pass your free time by hacking hundreds of solutions in Educational rounds ?

not much time needed, it's probably a script that automatically download source code , compile and run it , they only need good hacking tests , or if you feel lazy just randomly generate some tests and compare the output to a non hackable solution ,you can check TLE/RE errors too.

That's a legend thinking approach !

Wait, I never realised you can download solutions in text form during educational rounds! Well, well, well...

I do learn new things while trying to hack solutions. This type of thinking helped me to construct the worst test case for my own contest problem recently.

How did you download all this code at a same time??

Maybe he used a crawler

I get it sir

Hopefully it wont have geometry problems :)

We also have just discussed this topic. I plan to update all prior announcement blogs with this information after the outcome of present contest are up. Write My Essay For Me

I need to check the rules of ACM-ICPC. Can anybody send the link?

It turned out, that searching "ACM ICPC rules" gives some results.

https://icpc.baylor.edu/regionals/rules

https://icpc.baylor.edu/worldfinals/rules

i hope someday , somebody write a contest about DOTA 2 it would be so nice :D

Dead Game, Dead Game

I Love Dead Game

Getting Hired..

uwi modeWhen is this and is it rated?

Educational Round is not rated. And you can also check from Codeforces Calendar

Hi , This will be my first Codeforces contest !

please don't bomb the contest, we beg you, it's only educational to serve the country...

Please someone tell uwi to not hack this guys

LOl

You are DED

The days are gone forever when our enemies could blackmail us with nuclear bombs.

Scary.

Good luck to everyone!

Thanks

Time to

BOMBtest case #3 of Problem BYou are behaving very badly, Rocket Man.

We will have no choice but to totally destroy the problemset!

you can pass it and get ac if you add one line

Test 14 in E?

http://codeforces.com/blog/entry/54654?#comment-386830

What is test 14 in E?

If you are compressing the values, you should add (

r[e] + 1) to the values to compress, at least I did this and passedCan we solve that questions using Compression and BIT ???

I probably wrong , but i don't think so, we can't get the minimum of a range with BIT and do range updates at the same time.

there is a way to do that,but it is tricky to code and it is not worth using instead of seg tree :)

I actually implemented that method but somehow I'm getting a WA. I have used a BIT for the cumulative sum. Getting WA on 16th test case. Here is a link to the code. Can you have a look of what I might be doing wrong. https://code.hackerearth.com/0ec204e?key=4b7fb07878fac98d3c5bcc41899f3436

My solution is:

suppose the elements l[e], r[e] <= 10

^{5}If you add 1 to every element in the range [l[e], r[e]] for every e , you can check if a range is good checking if the minimum element in the range is 1.

Because if the minimum is 1 after deleting that range we gonna have at least a 0, what means that the number of moments increased.

Any reason why compression with l[i],r[i],l[i]-1,r[i]+1 works?

Basically, you have to see that some number may be 'lost', what I mean is that when we are compressing we are not considering the elements l[e] < X < r[e], for every e, so we can create a case were there is more that an range loses one of it's elements and after this our algorithm gives the wrong answer, but actually we don't have to take exactly all the X, if this situation gonna happen is because of there is two ranges with some intersection, so the values that matters are the borders of the ranges, it's not a good answer, but if it's not clear I can try to explain in a better way

this is a test like it

3

1 3

5 7

2 6

correct answer:-1

Thanks

How to solve E? (and why i'm getting RTE with a simple segtree?)

the seg tree dimenison is too little,it should be 4*2*MAXN

Oh, i see, thank you :)

I tried to solve it using segment tree with range sum updates and range min query first i do coordinate compression and then i will update from 1 to n all queries with +1 to their corresponding range and then i will start from 1 to n and at an i th position i will remove that update by adding -1 to that range and check if in that range iam getting any 0 if NO THEN that is a valid ans as it is not affecting others's //(using range min query ) but the problem is i was unable to implement it in time .and also can't we implement a segment tree with range sum updates and range min queries??

You don't need range min queries. What you need to know — is there any element on range equal to 1. Just access each element of your tree and build an array of prefix sums with amount of 1's on prefix, like this:

`prefixSum[i] = prefixSum[i-1] + (tree.get(i)==1)`

. Then some segment`[l; r]`

is an answer if`prefixSum[r] - prefixSum[l-1] == 0`

tnx , cool idea to solve that question(we don't even need a segment tree we can use partial sum trick ) . btw i have a doubt in general not regarding this question but can we code a segment tree with lazy propagation such that we can do range sum updates (i.e we can add a value v from l to r ) and we can do range min queries (i.e we can find minimum in that range from l to r ) in logN time .

I tried to solve D using treap, I think it is an overkill but it should work! I got RE on test 10 and 11 ... it's weird

I'm not sure, but it might be because you put the priorities as rand () (up to 32000 on CF compiler). If you extended the set of possible values, the possibility of two priorities being equal on adjacent positions (which most treap implementations consider 0) would dramatically decrease. I use treaps with rotations and in that implementation in function erase, if you have two neighboring nodes having the same priority and do not pay special attention to the case, you might end up with a loop. Let alone that such small values cut off the idea of normal distribution, so even if you hadn't gotten RE, you would've gotten TLE. Try to switch that line of the code with something like p = (rand () << 15) + rand ().

You are right! It worked. I completely forgot about that detail.

I must say, I have been very lucky because I have always used just "rand()" in these kind of problems.

Thanks!!

@San721, can you give me explanation sample test case for problem D?Problem statement aren't clear to me.

Actually, I did the same overkill :)

How can you reverse the segment using treap?

Each node should contain a bit which indicates whether you need to flip it or not. To flip a segment, split the treap into three parts (propagating the flips as needed), change the flip bit on the middle part, and then merge the parts.

Another approach is to build two treaps. One for the initial array and another for the reversed array. If you have to reverse a segment you swap the corresponding segments in these treaps.

very interesting problemset.

I laughed so hard when I saw SPFA_THE_BEST_ALGORITHM's nickname, knowing it is part of the solution to problem F :D

Simple solution to problem E, no data structures needed (other than array) 30592259

PS: I hope nobody hacks it !

just found a little hack, if you fix it I would try again, although the solution approach seems kinda correct to me :)

Sure ill try to fix it later (order needs to be x increasing then y decreasing), i also believe it to be a correct approach, but i seem to be unable to code without bugs lately.

Edit: fixed version, with the change previously described 30727493

Is there solution for D easier than treap solution?

Do the operation backwards. For every b, do the operations in reverse to find where the number would have started. Then print that number. Complexity is O(m * q).

Hi guys, I did join this website yesterday. and I am really happy for this. Few minutes ago I did submit my attempt to solve the problem A but I see

runtime error on test1.I am quasi sure that my solution is working well. I did use java. should I stop using things like demanding the user to enter an input "java.util.Scanner" ? please help me!

The solution is bellow :

Remove "System.out.println("Enter the number please");" and see if it goes away

Also you are supposed to output only "YES" or "NO".

how should i approach problem E? Thank you.

Create a map

mwhich will compress the indices. The interval [l,r] will be transformed tom[l],m[r+ 1] - 1. Now eitherltorinclusive is greater than 1. This works well if you already have a template prepared. :)l,r] with a set. If none of them are inside, then this TV is redundant.There is a simplier solution without indices compression and segment tree:

The main idea, that TV (l, r segment) is redundant if it fully overlapped by one or two consecutive segments (proof is pretty easy). So algorithm looks like:

30588470

Can you please explain why indices left — 1 and right + 1 are compressed along with left and right?

I followed the exact same approach but somehow I'm getting a WA. I have used a BIT for the cumulative sum. Getting WA on 16th test case. Here is a link to the code. https://code.hackerearth.com/0ec204e?key=4b7fb07878fac98d3c5bcc41899f3436

i used binary search and some preprocessing. 30619432

Hey! I am new to codeforces. Can anyone guide me ?

Start solving problemset starting from Div II A, B. Learn some algorithms and DS and then jump to Div I. Participating in contests is a must. Read other people's solutions and be most important be optimistic.

Because hacking others' solutions is too mainstream.

How to solve the problem D?I have no idea on data structure,could someone give me a little help?

Consider the number of queries is smaller in 100, we can calculate for every single query for the operations but not the whole sequence. As we are given the ending position of the number, we can calculate it's beginning position. For the operations,we can consider it in reverse order.

Let's call the position of the query is now x,and consider the operation done before it become x.

First. the operation reversed [l,r],then if the x is in [l,r] it should be l+r-x before this operation.

Second. the operation shift [l,r] ,then if x is in [l,r] it should be x-1 before this operation. but if it's l exactly it should have been r.

So you can solve the problem in O(nq).

Sorry for my poor English, if it's still not clear, you can ask again.

God bless you.

@pb0207, can you give me explanation sample test case for problem D?Problem statement aren't clear to me.Specially first operation isn't clear to me.

The first operation is a cylic shift which is that all the numbers in the interval [l,r] goes right except the number on the position r which goes to l.

That means for the array [1,3,2,4,5,6,7,9,8] if we do the first operation to the interval [2,5] , it would be [1,5,3,2,4,6,7,9,8]

The second operation means to reverse the interval.Which means if you do this operation to the interval,then you can find the previous interval by reading from right to left. And for more formal explanation the number on position l would be equal to number on r,and l+1 equal to r-1 ,etc.

And for the array [1,3,2,4,5,6,7,9,8],if we do the second operation to the interval [3,7] , it would be [1,3,9,7,6,5,4,2,8]

pb0207 Thanks for your time ,consideration and forthcoming response. Sample testcase; - 6 3 5 - 1 2 3 4 5 6 - 2 1 3 - 2 3 6 - 1 1 6 - 2 2 1 5 3

for 2 2 1 5 3 answer would be 3 3 1 5 2 Isn't it?

Yes, that's right.

This helps a lot thanks!

I was confused with this problem but now i get it! :')

As for data structure, you can learn Treap or Splay which can reverse the array.And you can calcultate the final array in O(logn) for each operation.

Hi pb0207 Do you know a good reference about treap and its reverse operation?? I've read a couple of pages about treap but they don't mention that!

As I mentioned here, you can use lazy propagation to flip a segment of a treap. See my submission for its implementation.

For problem B, can any body explain why this approach is wrong:

iterate over all pair and find the pair with minimal absolute difference between weights, then delete them and repeat the process.

This gives a WA, any proof why it's wrong.

Just my thought-

For example in optimal solution there's two index i and j which are taken as single boats.

So in your solution there's a possibility, that any of index (i or j) might give you minimum difference with some other index and you are using it in answer.

check 10 2 7 7 8 4 5 7 9 6 3 3 9 2 5 3 3 9 2 3 3

ans = 2

when you delete them ,you may get a bigger num.

Given it as a axis, when you choose c,d as the minimum pairs ,the remain {a,b,e,f}->you choose b-e but the [abcdef] minimum is |bc|+|de|<|be| but you alg got |cd|+|be|,that is greater than |bc|+|de|

When will be editorial published?

For problem E,why segment tree is not able to solve this problem?(I have change the array a for discretization) but I got WA on test 14.

The main idea I do is to add 1 in segment[l,r] and query the minimum value in this segment after all the add operations are done.Then if there is a segment whose minimum value can be greater or equal to 2 ,then this TV set is not needed.

It's that my fault in writing segment tree?But I'm so sure I could at least write a segment tree correctly...This is code...Please tell me what's wrong or just point out the solution itself is not correct...Thanks in advance...

i too taught segment tree. but seeing values of array, i solved it in another way. i used binary search. 30619432

Thank you for reply...But is there any monotonicity for binary search in this problem?I just think it's asking about whether there has a segment which have been covered by other segments completely...

Yes and you can search that segment using Binary search by doing some preoprocessing. let me explain it.

example:

3

1 2

2 3

3 4

lets sort this segments by l and if same then by r.

array = (1, 2) (2, 3), (3, 4)

now we will create new vector where we will store working time of tv's based on previous tv.

for example : (1, 3) (2, 5) as you can see the second segment (l2) is lying inside 1st segment. so we can write this as (1, 3), (4, 5). so here we converted the 2nd segment l to new time which is equal to r1 + 1.

if r1 + 1 > r2, this means that second tv is totally not needed so we can output this as answer. for example: (1, 3) (2, 3).

after building this new vector for out previous example it will look like this:

array = (1, 2) (2, 3) (3, 4)

newtime = (1, 2) (3, 3) (4, 4)

now for each segments in newtime find how many segments are there in array. if there are more than one then this segment is not needed. for this use binary search, find the leftmost segment and then find the rightmost segment. count = (rgt — lft) + 1.

OK,I got it! Nice solution! Thank you.

can anyone please tell me how to approach the problem B i tried all possible solutions from my side

Sort and then apply DP http://codeforces.com/contest/863/submission/30594941

why should they write greedy in tags i tried from dp but then i got confused else thanks for help

for example take this as example:

1 2 3 4 5 6. here you have to make 3 pairs such that abs difference is minimum.

first sort then the optimal way is to select (1, 2) (3, 4) and (5, 6) as pairs. why not (2, 3) as a pair. see if you select 2 and 3 as pair then only option for 1 is to select 4 or 5 or 6 which is far. so they will give huge distance. so select the nearest one.

now coming in question for every possible 2 single boats select the others boats and do the above process. 30608352

When will the editorial be posted? Hacking phase is over already.

I need editorial of problem F.Can anyone please explain how to model flow network for this problem.

How to solve G?

Sorry for the late editorial, it is published now.

I'm sorry but where exactly can I find it? I don't see any link to it

Here is the link to the editorial

anyone can help check whats wrong with my solution for problem E, got RTE for 16th test case. http://codeforces.com/contest/863/submission/30694287

The problem is in cmp function. Your comparator must always be like: if cmp(a, b) then !cmp(b, a).

UPD: And one more mistake is in if-statement in main function.

is there answer?

This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work. color switch