### GlebsHP's blog

By GlebsHP, history, 21 month(s) ago, translation, ,

Hello everybody!

Tomorrow round will be held using problemset of Moscow programming competition for school students of grades from 6 to 9. Do not be tricked by the age range of the participants, Moscow jury always tries its best to select interesting problems of various topics. Problems were developed by feldsherov, ch_egor, halin.george, ipavlov and GlebsHP.

Hope to see you in the standings!

P.S. Scoring distribution is standard.

UPD Congratulations to the winners!

UPD2 Problem analysis is here.

•
• +241
•

 » 21 month(s) ago, # |   +10 Auto comment: topic has been translated by GlebsHP (original revision, translated revision, compare)
•  » » 21 month(s) ago, # ^ |   -37 Этот раунд рейтинговый? Просто в тексте не было информации об этом!
•  » » » 21 month(s) ago, # ^ |   +11 рейтинговость раунда определяется состоянием системы codeforces)the rating is determined by the round system status codeforces)
 » 21 month(s) ago, # |   -16 more details?
 » 21 month(s) ago, # |   -25 will this round be rated??
 » 21 month(s) ago, # | ← Rev. 2 →   +273 programming competition for school students of grades from 6 to 9. I was playing Mario when I was in the sixth gradeGod bless my childhood
•  » » 21 month(s) ago, # ^ |   +3 I practice for typing when I am grade 6. Who bless my childhood? please!
•  » » 21 month(s) ago, # ^ |   +4 G0D_FaTHER what were we doing when we were in 6th class ? I remember spending time in school ground!
•  » » 21 month(s) ago, # ^ |   +23 some of this students are red on codeforces. for example voidmax he is 9 grade btw (he was red)
•  » » » 21 month(s) ago, # ^ |   +3 Oh no... maybe they have to make a div1 round for them not div2
•  » » 21 month(s) ago, # ^ |   0 Man ,I didn't have PC when I was in the sixth grade :(
•  » » » 21 month(s) ago, # ^ |   +15 I didn't know what's a computer when I was at 6th grade!
•  » » » » 21 month(s) ago, # ^ |   +48 That's nothing! When I was in 6th grade, we had to walk to school 30 kilometers every day, uphill both ways!
•  » » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 As a kid I lived in Manhattan and it was mandatory to walk a different route every day!
•  » » » » » » 21 month(s) ago, # ^ |   +24 that's when you realised how important dp and graphs are.
•  » » » » » 21 month(s) ago, # ^ |   +10 both ways uphill? :) I had only one way uphill
•  » » » » 21 month(s) ago, # ^ |   0 Same here ....I first saw computer when i was in 11th class
•  » » 21 month(s) ago, # ^ |   0 I started learning programming at 5th grade because our "modern" PC died and qBasic was about the best "game" I managed to find for the older one xD
•  » » 21 month(s) ago, # ^ |   0 Programming skills relation with experience can not be denied
 » 21 month(s) ago, # |   -7 Why is my 3rd hacking attempt still waiting while my 5th attempt has been judged?
•  » » 21 month(s) ago, # ^ |   +78 LOL this isn't the blog of the round #400
•  » » » 21 month(s) ago, # ^ |   +39 Oh sorry
 » 21 month(s) ago, # |   -7 Can you change the contest time, please? .. In Egypt we have a weekly prayer time in that time, an hour after that will be perfect.
•  » » 21 month(s) ago, # ^ |   +100 The contest time is bounded by the time of onsite competition. It should start after the onsite competition has started and finish before it has finished. I'm sorry, but there is no way we can change the competition time.
 » 21 month(s) ago, # |   +13 I hope to change the time as it time of prayer in most of arabic countries
 » 21 month(s) ago, # | ← Rev. 2 →   0 This is the worst timing you can put for arabic muslims :D
•  » » 21 month(s) ago, # ^ |   +10 The round is not for Muslims.
 » 21 month(s) ago, # |   0 number of problems ?
•  » » 21 month(s) ago, # ^ |   +1 Email says 5.
 » 21 month(s) ago, # |   +29 Seems like the King got resurrected .
 » 21 month(s) ago, # |   0 change the time please. it's our week pray time .
•  » » 21 month(s) ago, # ^ |   +8 Then do not pray.
•  » » » 21 month(s) ago, # ^ |   0 it's not your business .
 » 21 month(s) ago, # |   0 it's too early :(
 » 21 month(s) ago, # |   +3 These days number of problems <= number of problem setters. Get prepared to read long problem statements and strong pretests. I wish I perform well :)
 » 21 month(s) ago, # |   +23 It seems like I am the ONLY arab who will participate in this contest
•  » » 21 month(s) ago, # ^ |   +1 Why aren't you in the same situation as the others?
•  » » » 21 month(s) ago, # ^ |   +5 not the same religion
•  » » 21 month(s) ago, # ^ |   +8 I wanna take a moment of silence to thank god who created me an atheist so i can peacefully take part in today's round :D
 » 21 month(s) ago, # |   +7 Canada I am coming.
•  » » 21 month(s) ago, # ^ |   0 Why canada?
•  » » » 21 month(s) ago, # ^ |   0 Why Nicky Minaj?EZ Silicon.
•  » » » » 21 month(s) ago, # ^ |   -9 FYU, Nicky Minaj is "QUEEN OF RAP"
 » 21 month(s) ago, # |   -17 you will notice a decrease of contestants because of the Arabian issuehope to change the time of the contest
•  » » 21 month(s) ago, # ^ |   +71 Please, keep in mind that Codeforces always tries to vary competitions time to give more people an opportunity to participate in at least some of the contests.
•  » » » 21 month(s) ago, # ^ |   +22 Exactly. As much as the typical time may work well for arabs, russians and other europeans, the contest usually ends at 2-5am in Korea, Japan, etc. This is a global community and any time chosen would not work for some people. Also it is well explained above why this time cannot be changed as it has to work around the on-site competition.
•  » » 21 month(s) ago, # ^ |   +2 But when most of competitions carry out in night time for east regions, it's ok for you and you don't have any problems. Think about others sometimes.
 » 21 month(s) ago, # | ← Rev. 2 →   +41 This happens when you don't thank MikeMirzayanov, warning! :P
 » 21 month(s) ago, # |   -84 To all the people who have pray time during the contest: which one is more important, Codeforces or praying in the name of some god who might or might not exist? I personally think that skipping one day of prayer is justified ;), this can be a secret between you and me, nobody else has to know.
•  » » 21 month(s) ago, # ^ |   +14 Hey!!!
•  » » » 21 month(s) ago, # ^ |   +9 Why you are not legandery grandmaster god :p
•  » » » » 21 month(s) ago, # ^ |   +6 god is a specialist in screwing my life up. Thank you so much :)
•  » » » » » 21 month(s) ago, # ^ |   +1 I like you!
•  » » 21 month(s) ago, # ^ |   0 It depends on which category you put yourself — theist, A-theist, Deist, Pantheist .I am the last one so I don't give a shit about prayers or believing in some supernatural shit.
 » 21 month(s) ago, # |   +25 Thank God I don't believe in God.
•  » » 21 month(s) ago, # ^ |   -6 We need more people like you!
 » 21 month(s) ago, # |   +4 Since the king is back, I hope this round will go smoothly :)
 » 21 month(s) ago, # |   +8 I don't like long problem statement , please try to keep it short like atcoder!
 » 21 month(s) ago, # |   0 How many to problemset?
•  » » 21 month(s) ago, # ^ |   +6 Only one problemset :D
•  » » » 21 month(s) ago, # ^ |   +1 LOL
 » 21 month(s) ago, # |   -45 Can you change the contest time, please? An hour after that will be perfect.
•  » » 21 month(s) ago, # ^ | ← Rev. 2 →   +1 Before writing such comments, pls read the previous comments about it! There are only 39+1 comments till now.P.S sorry for my poor English :)
 » 21 month(s) ago, # |   -27 Is this round will be rated?
•  » » 21 month(s) ago, # ^ |   +9 Yes this round will be rated....
 » 21 month(s) ago, # |   0 Will CF beat the tortoise today?
 » 21 month(s) ago, # | ← Rev. 3 →   0 don't give me " I don't like it. " pls. :-( I'm just a little boy with big dreams.
 » 21 month(s) ago, # |   +34 Rating prediction for this contest could be found here (after contest begins)Extensions: About CF-PredictorGood luck & high rating for everyone!
 » 21 month(s) ago, # |   0 I hope the round will be interesting.Good luck to all participants!
 » 21 month(s) ago, # |   +9 points distribution?
 » 21 month(s) ago, # |   0 How to solve D?
•  » » 21 month(s) ago, # ^ |   +4 Come from back and do this : string s = v[i]; while(s > v[i+1])s.pop_back(); v[i] = s; I don't know whether this will pass sys tests
•  » » 21 month(s) ago, # ^ | ← Rev. 2 →   +1 Iterate from (n-1)th string to 1st string, go on comparing with next string and trim this string till it is not greater than the next one.
•  » » » 21 month(s) ago, # ^ |   +1 But since n can be 5*10^5 and length of string can be 5*10^5,won't that solution with its ~ 2.5*10^11 operations be waaaay to slow? (in worst case)
•  » » » » 21 month(s) ago, # ^ |   +1 sum of lengths of all strings is 5e5
•  » » » » » 21 month(s) ago, # ^ |   +1 Thanks, apparently I need to pay closer attention to the problem statement.
 » 21 month(s) ago, # | ← Rev. 2 →   -23 Best Div2 Round ever?
 » 21 month(s) ago, # |   +54 I think B is harder than D ...
•  » » 21 month(s) ago, # ^ |   +6 If RoyalWyvern above is correct I agree. Had only 13 minutes left after A, B and C. Normally I quit, but I thought what the heck... Past pretests on D... |-)
•  » » » 21 month(s) ago, # ^ |   0 I had only 10 minutes left after A,B,C. I finished coding D 1 minute late.
•  » » » » 21 month(s) ago, # ^ |   +1 Well, at least you solved D 2 minutes quicker than I did!
 » 21 month(s) ago, # | ← Rev. 2 →   -32 My first comment....Please Upvote me
 » 21 month(s) ago, # |   +2 How to solve E?
•  » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Make a set of a,b,h using set < pair > > where first element of pair is b and second is pair(a,h) then sort the set. Then apply dp a[next_i] < b[i] check for the maximum possible height.
•  » » » 21 month(s) ago, # ^ |   +7 I don't think, this greedy choice will work here.
•  » » 21 month(s) ago, # ^ |   +4 Sort by B values. Then dp[i]=dp[next[i]]+height[i] where next[i] is the nearest ring to the i'th ring such that a[next[i]]
•  » » » 21 month(s) ago, # ^ |   0 What do you mean by the "nearest". What is the order on ai?
•  » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Sorry if my answer was not clear. The ordering on rings is on the basis of b values. Nearest ring for i'th ring is j'th ring such that j>i and j is the least number such that a[j]
 » 21 month(s) ago, # |   +5 My exact same solution gave me AC in c++ whereas it was giving me TLE in python. This wasted my 15 mins and also 1 incorrect submission
 » 21 month(s) ago, # |   0 My correct output is weirdly getting wrong answer on 1st test case itself -_-Looks like CF knows dark magic to make correct output wrong.Is D to be solved with trie? I constructed the trie from nth element to first.
•  » » 21 month(s) ago, # ^ |   +1 not needed ... keep the last string as it is... then greedily check the max prefix you can keep from bottom to top
 » 21 month(s) ago, # |   +1 Why WA in pretest 1 in D? all samples matched... :/
•  » » 21 month(s) ago, # ^ |   0 Same with me.
•  » » 21 month(s) ago, # ^ |   -23 First test may be different from the first example.
•  » » » 21 month(s) ago, # ^ |   -6 No it's not. I asked them. In custom invocation also, it's producing wrong answer instead of correct one for sample test case 1. Something's wrong with CF server.
•  » » » » 21 month(s) ago, # ^ |   0 It might be that CF compiler does not give the same answer for the test as yours.
•  » » 21 month(s) ago, # ^ |   0 It may be because the way you outputed the strings. Initially i was changing all the characters that shouldn't be outputed to '\0' and it didn't work,but the next time I just printed the characters I had to and ignored the others(and passed the pretests)
•  » » » 21 month(s) ago, # ^ |   -8 I checked that too. The problem is with server. I ran custom invocation, and my variables are getting incorrectly assigned on CF servers. I had a variable whose value I explicitly set to 0, but CF is taking it to be 1.
•  » » » » 21 month(s) ago, # ^ |   +5 i dont think there is a problem w cf server if it is only your code that is running wrongly. Maybe there is some ambiguity somewhere? why not share your code for us to find out?
•  » » » » » 21 month(s) ago, # ^ |   +1 http://ideone.com/w9V6KYRun this code on test case 1.My output from custom invocation is this output from custom invocation5 8 4sid=3 len[sid]=1 i=00x2140dfc82sid=2 len[sid]=1 idx=12sid=1 len[sid]=1 idx=11 1 11 1 1 # # # ===== Used: 0 ms, 16220 KB
 » 21 month(s) ago, # |   +113 First div 3 round :)
•  » » 21 month(s) ago, # ^ |   -16 I disagree. For me it was Div 1.89 =)
•  » » » 21 month(s) ago, # ^ |   0 So you are claiming this is harder that the usual div 2 round?
•  » » » » 21 month(s) ago, # ^ |   +4 Yes, for me it was harder than usual.
•  » » » » 21 month(s) ago, # ^ |   +14 I think A and B are harder than usual but D and E are easier.
 » 21 month(s) ago, # | ← Rev. 2 →   0 i tried to hack a solution using generator but it was showing some return 3 error from validator.exe Here is the program ,what is wrong in it generator codeint main(){ std::ios::sync_with_stdio(false); cout<<2<<" "<<50000-2<
•  » » 21 month(s) ago, # ^ | ← Rev. 8 →   0 After sync_with_stdio(false), you cannot mix cout and stdout. Calling fflush(stdout) might be the problemEDIT: Nevermind, it seems to be another problem
•  » » » 21 month(s) ago, # ^ |   0 endl automatically does that. Why did he even used that. :P
•  » » » 21 month(s) ago, # ^ |   0 no ,initially fflush was not there, I added fflush when it was showing error I feel there are extra spaces at end of rows of input Does i care about those extra space?
•  » » » » 21 month(s) ago, # ^ |   +5 There shouldn't be extra spaces in the end of the line. Validator checks for it.
 » 21 month(s) ago, # |   +8 When you spend all your time solving C and then realize that D was easier(atleast for me) and should have tried that.
•  » » 21 month(s) ago, # ^ |   0 Cannot agree more. Even E is easier than C
•  » » » 21 month(s) ago, # ^ |   0 I just saw the problem E. Is it graphs and CC?
•  » » » » 21 month(s) ago, # ^ |   0 I cannot code it in time (cuz my stupidity makes me waste around 40+ mins on problem C). However, I am pretty sure it is sorting, dp and segment tree.
•  » » » » 21 month(s) ago, # ^ |   +1 Its on simple greedy and sortings
 » 21 month(s) ago, # | ← Rev. 2 →   0 How do you solve C without using bitsets? They make the total complexity of my submission O(k*m/64), and that probably won't pass in 1 second ;( upd: yep, it did not
•  » » 21 month(s) ago, # ^ |   0 I used segment trees with range max query and it passed pretests.
•  » » » 21 month(s) ago, # ^ |   -10 Overkill
•  » » » » 21 month(s) ago, # ^ |   0 How did you do it ?
•  » » 21 month(s) ago, # ^ |   +4 For each row i calculate min row that can be reached, call it mni. Then if mnr <= l then answer is yes else no.
•  » » 21 month(s) ago, # ^ |   +6 p[i] — the first index where an increasing sequence begins, which comes to the i (this sequence can go on). Then checkif (p[r] <= l) answer is Yes;
•  » » » 21 month(s) ago, # ^ |   0 Oh, thanks, now I feel really stupid...
•  » » 21 month(s) ago, # ^ | ← Rev. 6 →   +6 You can store in the array the ranges with the maximum size, that contain sorted column. int range[100100]; // range[left] gives right side of the range: int right = range[left] ... while (k--) { int l, r; cin >> l >> r; bool inside = range[l] >= r; cout << (inside ? "Yes" : "No") << '\n'; } 
•  » » » 21 month(s) ago, # ^ |   0 how do you compute range[]? Isn't computing it O(n^2) making it TLE?
•  » » » » 21 month(s) ago, # ^ |   0 what I ment was O(n*m) making total running time O(n*m*k) ~ 10^10
•  » » » » » 21 month(s) ago, # ^ |   0 But you only need to compute it once, which gives the time of O(n*m + k)
•  » » » » » » 21 month(s) ago, # ^ |   +1 Thanks, I think I need to go back to sleep.
•  » » » » 21 month(s) ago, # ^ | ← Rev. 3 →   +8 Look at the example. We can split this matrix into disjoint sorted columns:We read this matrix from top to bottom, row by row. When we encounter a value which is smaller than the previous value in that column ( if (val < prev_val[col])) that means we have just met the right end of some sorted range. For example, look at the first column: 1 3 4 5 4. After reading first 4 values 1 3 4 5 we encounter a value 4 which is smaller than the previous value 5. Now when we've found boundaries of the sorted interval 1 3 4 5, we should record them. We know that this interval started at l and we know that it has finished at r. We do a loop for (int i = l; i <= r; i++) and record what we have discovered: for (int i = l; i <= r; i++) range[i] = r; How many times will we touch an element of the matrix? At most 2 times. The first touch happens when we read it. The second touch is when we record the interval with a for loop.
•  » » » » » 21 month(s) ago, # ^ |   0 Thank you for the amazingly detailed answer.I think we can even go bottom-up from n-1 to 0 for each column j, so that every time we descend we remember the largest row index we started descending from and update each a[i][j] accordingly, only needing a single for loop.Thanks again!
•  » » » » » » 21 month(s) ago, # ^ |   0 When we go top down, we don't need to store the original matrix. So top-down traversal should have a smaller memory footprint than bottom-up.
•  » » » » » » » 21 month(s) ago, # ^ |   0 I understand range[l]>=r but why range[l-1]>=r?
•  » » » » » » » » 21 month(s) ago, # ^ | ← Rev. 3 →   0 I don't know :)In the original idea I came up with during the contest I wanted to find 2 intervals which are closest to the given index l. So, I have thought about the following configuration: [l1, r1] l [l2, r2].I wanted to check that I fall inside of either the first interval or the second interval.But in the algorithm that I have described we need to check only one interval. I will edit my comment.
•  » » 21 month(s) ago, # ^ |   +1 I solved it by just traversing the 2d array and maintaining a index of minimum and maximum element http://codeforces.com/contest/777/submission/24969962
•  » » 21 month(s) ago, # ^ |   +6 You can use Dynamic Programming. You have dp[i][j]-the longest non-decreasing subsegment(continous subarray) of the j-th column that ends in the i-th line.To get it,you simply look in dp[i-1][j] and check if a[i-1][j]<=a[i][j]. If it's true,dp[i][j]=dp[i-1][j]+1,else dp[i][j]=1. Also,you need best[i]=the maximum of dp[i][k] with k in range 1..m At each query,you check if best[r]>=r-l+1 and print the answer depeding on the condition.
•  » » 21 month(s) ago, # ^ |   0 store in one dimension array
•  » » 21 month(s) ago, # ^ |   0 3 cases: 1) n==1 YES for all requests 2) m<=1000 you can over 1000 colomns all one in O(1) * 100 000=k so it take O(10^8) 3)m>1000 ,so n<= 100 so I just build table answer[100][100] for all possilble l and rhttp://codeforces.com/contest/777/submission/24975294
 » 21 month(s) ago, # |   0 Is it okay to ask some questions here? I have joined the contest now and also yesterday but I was unable to submit atleast one solution. I wonder why my rating didn't go down yesterday. Will my rating go down now?
•  » » 21 month(s) ago, # ^ |   +4 If you haven't made any submissions, your rating will not change.
•  » » » 21 month(s) ago, # ^ |   0 Oh. I see. Thank you very much shreeyash.g :-)
•  » » 21 month(s) ago, # ^ |   +1 Your rating wont be effected if you dont submit anything.
•  » » 21 month(s) ago, # ^ | ← Rev. 2 →   +1 Unless you have at least one submission you are not taken into consideration for rating changes.
•  » » » 21 month(s) ago, # ^ |   +4 "one submissions" xD
•  » » » » 21 month(s) ago, # ^ |   0 Yeah, happens :D
 » 21 month(s) ago, # |   -11 KAN please look into what's weird with D? Correct solutions are getting wrong answer!
•  » » 21 month(s) ago, # ^ |   0 Can you please highlight an instance ?
•  » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 I've explained it hereand in this thread
 » 21 month(s) ago, # |   +8 What was the 4th pretest of E about?
•  » » 21 month(s) ago, # ^ | ← Rev. 2 →   +3 sorting by bi > bj, ai < aj not ai > aj
•  » » » 21 month(s) ago, # ^ |   0 But why the order of a matters? Doesn't the prefix length where we search for the maximum depend only on b? Since any processed aj lesser than b should be ok.
•  » » » » 21 month(s) ago, # ^ |   +14 Yes, it does matter. Unfortunately, I only realized it in the last 2 minutes of the contest. Consider rings with the same b, then we should end the segment with the smallest possible a so that we can use more rings later.
•  » » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Edit: nvm.
•  » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   +3 This order matters because, since a smaller ai can cover many more rings to come, hence, for same 'b', a ring with smaller 'a' should come later, so that it adds up to a greater dp value. Otherwise, your answer can be lesser than it should be.
•  » » » » 21 month(s) ago, # ^ |   0 Thank you!
•  » » » 21 month(s) ago, # ^ |   0 Couldn't figure it out till the end,was checking my segtree implementation for every WA. Anyways, it was easy but good problem.
 » 21 month(s) ago, # |   0 When you about to click submit button for D and the contest ends. Hope my solution was wrong.
 » 21 month(s) ago, # |   +11 With some Arabs praying and some other people sleeping or working Codeforces was deliciously responsive today! Thanks!
 » 21 month(s) ago, # | ← Rev. 2 →   0 The test should be at most 256 kb .Then how can i hack o(n*m*k) solutions at C or o(n*l) solutions at D?
•  » » 21 month(s) ago, # ^ |   0 Write generator.
 » 21 month(s) ago, # |   +32 Looks like the Div.2 rank.1's solution was written by multiple people.
•  » » 21 month(s) ago, # ^ |   +22 ha ha... 5 codes and 4 different templates :p They could've atleast used the same template.
 » 21 month(s) ago, # |   -42 My request to feldsherov, ch_egor, halin.george, ipavlov, GlebsHP and KANPlease look into D. Something's wrong with CF server!Here's proofhttp://codeforces.com/contest/777/submission/24975275http://ideone.com/Mxgyyt -> exactly same node, not even a character has been changed. You can compare diff if you want.Results are so different!I don't want to lose points because server's fault. Please look into it!Thanks!
•  » » 21 month(s) ago, # ^ |   +1 It's not server's fault. You have UB somewhere.
•  » » » 21 month(s) ago, # ^ |   -19 No. I have checked with custom invocation. My array len[] is getting incorrectly assigned inside insert function.
•  » » 21 month(s) ago, # ^ |   +20 You are blue, but u talk like a complete newbie. By now, you should know that compiler versions differ on different Online platforms, and thus produce different outputs. Don't u feel like taking a second off and thinking about what may have gone wrong before blaming the CF server and taging all admins ?This is sheer stupidity, and complete newbie attitude. How many times have we seen this same query from multiple multiple people ?
•  » » » 21 month(s) ago, # ^ |   -17 I challenge you to find a UB in my code! If you do, then you can call me newbie :) Deal?If you can't find bug, then you by default admit I am right, and I should get my ratings back.
•  » » 21 month(s) ago, # ^ |   +15 You used the memory returned by malloc without initializing it, which may behave differently by environments.
•  » » » 21 month(s) ago, # ^ |   -19 Okay fine. But I've also tested the code with explicitly initializing present = 0 and all children set to NULL in custom invocation. The bug didn't go away.
•  » » » » 21 month(s) ago, # ^ |   +6 No. As I just tested, changing malloc to calloc killed the bug. Besides, your code is TLE even after fixing the bug.http://codeforces.com/contest/777/submission/24980602
•  » » » » » 21 month(s) ago, # ^ | ← Rev. 2 →   -16 What a strange contest for me :/Thank god for TLE XD
 » 21 month(s) ago, # |   +16 Anyone else solved E with sorting and a stack? I can explain my solution if there is interest.
•  » » 21 month(s) ago, # ^ |   0 Really? How? I used segment tree + heap, but I'm pretty sure BIT can be used instead of segment tree.
•  » » » 21 month(s) ago, # ^ | ← Rev. 3 →   +11 Well, here's a description of my solution:First, you sort the disks in a descending order, prioritizing the variables in the order b, a, h. (Note: my code actually swaps the names of a and b) Then, you go through the disks in the sorted order. You remove as many disks as you need to from the stack, until you can place the currently processed disk on top. You maintain the current total height of the stack, and also a maximum achieved height. The maximum height is the answer.I couldn't come up with a proof for this, but neither could I come up with any counter-example, and it surpassed all the tests. It just felt like it could work.
•  » » » » 21 month(s) ago, # ^ |   0 I also have no idea why that works :)
•  » » » » 21 month(s) ago, # ^ |   -11 I was 30 minutes late to the round. I solved from a fake id. I did this way :)This is not cheating :P I didn't submit from multiple id's :P
•  » » 21 month(s) ago, # ^ |   +1 same here :)
 » 21 month(s) ago, # |   +3 The first time I have solved 4 problems.
•  » » 21 month(s) ago, # ^ |   +40 So, I assume you used 0-based indexing when you said that?
 » 21 month(s) ago, # |   +35 My skill is like Petr's or tourist's when they were in 6th grade.
•  » » 21 month(s) ago, # ^ |   +82 I think tourist was much better when he was in 6th grade :P
•  » » 21 month(s) ago, # ^ |   +39 tourist won Belorusian olympiad when he was in 6th grade. Look
•  » » » 21 month(s) ago, # ^ |   +16 tourist got 225/600 in Belarusian Olympiad when he was 7 years old. What the fuck?
•  » » » 21 month(s) ago, # ^ | ← Rev. 2 →   +3 When God made tourist"A spoon of kindness... perfect""A bit of handsomeness... incredible!""And just a pinch of coding skills..... oops fuck. I messed it again"
 » 21 month(s) ago, # |   0 A: ACB: FST (WA)C: FST (TLE)What happened to my brain?
•  » » 21 month(s) ago, # ^ | ← Rev. 9 →   +4 A:WA B:WA C:AC what happend to my brain??
•  » » 21 month(s) ago, # ^ |   0 Same here. I felt B harder than C. Finally B(WA), C(TLE). I observe more failure rate in this contest after pre-tests.
 » 21 month(s) ago, # |   0 How to solve E with segment tree?
•  » » 21 month(s) ago, # ^ |   +3 Compress the inner and outer radiuses so that all radiuses are less than 200000.Sort all the rings by outer radius in the decreasing order. In the case of a tie, sort them by the inner radius, also in the decreasing order.For each ring, calculate the maximum height of a tower with that ring on top. This is obviously the height of the ring + maximum height of towers where the top ring has inner radius less than the outer radius of the current ring. Solution with segment tree becomes obvious now.
 » 21 month(s) ago, # |   +27 I am shocked by the programs of THE RK1. I don't think a people will code in more than FOUR different code styles. I don't mean he has cheated,just curious.
 » 21 month(s) ago, # | ← Rev. 3 →   +38 I know a little about the rank 1[user:Mr.Stream] but I know he is about 60 years old. What an unbelievable achievement!!! Could i make friends with you? Thx!
•  » » 21 month(s) ago, # ^ |   +13 you will make friends with 4 people QwQ
•  » » 21 month(s) ago, # ^ |   0 make friend with me instead :)XD
•  » » 21 month(s) ago, # ^ |   0 Although the rank 1 is used the name of XianYou Xu,but I guess he is not the 60 years old man,maybe it is just a joke by his student.
 » 21 month(s) ago, # | ← Rev. 3 →   +5 I'm too stupid.I use memset and strlen() in the for loop.And I got TLE in C and D
 » 21 month(s) ago, # |   +13 Contest was easier than usual, D was little easier than C.
 » 21 month(s) ago, # | ← Rev. 2 →   0 About the Rank 1...There was a legendary man called HangZhou Blade Master...and now you see that...
 » 21 month(s) ago, # |   +8 Actually i can't why My E Programme TLE ON 13..... And i want to say congratulation to rk1[Mr.stream]
 » 21 month(s) ago, # |   0 D is the worst question, why is it D, I think A is harder than D, liked solving C. Why is it like that.
 » 21 month(s) ago, # |   +22 A shoutout to all those who stumbled at pretest #4 in problem E cuz of the sort :D
 » 21 month(s) ago, # |   0 When can we see the solutions？
 » 21 month(s) ago, # | ← Rev. 3 →   0 Could anyone please tell me why my solution on E got a Wrong Answer on test 39? I tried to solve it by using set and multiset instead of a segment tree,but it failed. Is it possible to solve E this way?Thank you! Here is my solution : http://codeforces.com/contest/777/submission/24972634
•  » » 21 month(s) ago, # ^ |   +5 I came up with a group of input to prove my code incorrect. And I found the elements I intended to put into the set actually failed to be inserted. Can anybody tell me why?Here is the data:5 2 3 12 4 12 5 12 8 11 2 1The expected answer is 4,but I got the incorrect answer 5.
 » 21 month(s) ago, # |   0 Some interesting bug I discover. So my submission 24970450 got wrong answer on pretest one. But when I run it on custom invocation, I got the same answer. #b#big#bigWhereas the output from the judge is #b??#big#bigI know the error comes from my failure in resizing the string, but shouldn't the custom invocation gives the same output as the judge?
•  » » 21 month(s) ago, # ^ |   0 I guess, that "??" is just to show, that there are space characters. In custom invocation there are 2 spaces instead of "??"
•  » » » 21 month(s) ago, # ^ |   0 but why does whitespace matter when u print? i can always print excess whitespace at the end of the line and still get AC
•  » » 21 month(s) ago, # ^ |   0 '\0' and ' ' are different.........
•  » » » 21 month(s) ago, # ^ |   0 that should make my code even more correct. cause cout will automatically ignore everything after '\0'...
•  » » » » 21 month(s) ago, # ^ |   0 char[] and string are different. string won't ignore '\0'.It records the length directly.
•  » » » » » 21 month(s) ago, # ^ |   0 read linkIt says there "This function overloads operator<< to behave as described in ostream::operator<< for c-strings, but applied to string objects."If you dont believe me, try writing something like: string str = "Chestnut\0Zun"; cout<
•  » » » » » » 21 month(s) ago, # ^ | ← Rev. 3 →   +3 char[] ends with '\0',so when you convert char[] to string,it will only convert chars before '\0'.You can try this string str = "Chestnut-Zun"; str[8]='\0'; cout<
•  » » » » » » » 21 month(s) ago, # ^ |   0 ok, looks like i am wrong then. This is indeed interesting, I got ChestnutZun when I print to my terminal(which looks like '\0' being ignored) but I got 4368 6573 746e 7574 005a 756e 0a when I print to a file. Do you have any idea why?
•  » » » » » » » » 21 month(s) ago, # ^ |   0 Maybe '\0' was ignored by your terminal.It looks like a space on mine(Windows cmd).
•  » » » » » » » » » 21 month(s) ago, # ^ |   0 i run it on my terminal, cf and ideone though.all of them ignored '\0'
•  » » » » » » » » » 21 month(s) ago, # ^ |   0 most of browsers ignore it too..... Custom invocation and online ide don't escape '\0',but submissions page do....
•  » » » » » » » » » 21 month(s) ago, # ^ |   0 oh ok, thanks.
 » 21 month(s) ago, # |   +5 Is it possible to use fenwick tree instead of segment tree for problem E? I'm got AC with segment tree but WA with fenwick. However, I've used fenwick on prefix RMQ problems before (i.e. when we query for prefixes only) and they've all passed. So now I'm wondering if it's possible or not?
•  » » 21 month(s) ago, # ^ |   +6
•  » » » 21 month(s) ago, # ^ |   0 Maybe this is a stupid question, but why was it necessary to group a and b into the same array and operate fenwick on that array? Wouldn't it be correct to update on the indices of the given array from input?
•  » » » » 21 month(s) ago, # ^ |   0 The values are large enough and distributed randomly, so maybe this is a stupid question, but how can we use indices instead of real values?
•  » » » » » 21 month(s) ago, # ^ |   0 Maybe my algorithm is stupidly wrong, but this is what I did so far 24985290. Code is easy to read IMO
 » 21 month(s) ago, # |   0 Can anyone explain me the complexity analysis of my solution to problem C. Submission Link My approach was to store all the increasing sequences in in each column ans push the starting and ending points int the map, along with size of sequences and the column in which it occurs. I also store the length of increasing sequences in "pts" vector. This vector is then sorted and duplicates removed from it. Now, for a given query, I simply iterate for all possible length >= (r-l+1) and check if I can get an answer from it. For a given "j", the answer exists only when the pre-computed range covers the entire length. This can be broken down into 3 cases (Similar to linear inequalities). If answer is found at any point of time, I stop the process else I brute force for all possible values of "j" and all possible positions in the matrix. I think this solution of mine can give TLE on some cases where number of answers "NO" is very large. But even I was not able to come up with a test case where my solution fails. (I have tried this technique in few questions earlier too, but never failed). But still can anyone help me in analysing the complexity of my solution. ?
•  » » 21 month(s) ago, # ^ |   0 Yeah, This does seem like it should have TLE'd. Since your query answering time can possibly be linear. So your complexity should be n*m*Log(n*m) + n*m*kFormer is for the preprocessing on finding non decreasing sequences, while latter is for query answering. As for each of the K queries, in the worse case you might have to iterate through all of the n*m (max possible number of sequences) to find your answer.
•  » » » 21 month(s) ago, # ^ |   0 Now, I feel the complexity analysis can go as follows. The are sqrt distinct values below given N. So, in most cases, it perform query in O(sqrt(n)). But there is one particular case where it will TLE. The case is as follows. All the columns should be strictly decreasing. So cnt in this case is 1 everywhere. Now, if each query is (n, n), then k in my case will be 1 and I will have to iterate through each of the (n-1)*m grid points to tell the solution.
•  » » » » 21 month(s) ago, # ^ |   0 I don't get how you got sqrt distinct values ? sqrt(n) distinct values of what ?
•  » » » » » 21 month(s) ago, # ^ |   0 Number of distinct values in "pts" vector.
•  » » » » » » 21 month(s) ago, # ^ |   0 Only iterating distinct values >=(r-l+1) isn't gonna get you the answer right ? You need to know the starting point too. So in the worse case it is still n*m*k right?Even if for each distinct size length the list of starting indices is sorted so you can binary search for the query start. It still adds another Log factor to the sqrt, which shouldn't pass the time limit.
 » 21 month(s) ago, # |   0 There has been some time since a saw sneaky pretests like these. They were all really light weighted and I forgot how painful it's to discover it after the contest is over. Yesterday I was Specialist, today I'm sad.=(
 » 21 month(s) ago, # |   +13 What's about announcing the winners of the contest?
•  » » 21 month(s) ago, # ^ |   0 It's annoying when you are in Top 5 of Div. 1 participants, but author announced only winners from Div. 2.
•  » » » 21 month(s) ago, # ^ |   +23 I think, it was on purpose just because of my comment.
 » 21 month(s) ago, # |   +2 Waiting for the editorial! Someone please tell me how to do problem C??
•  » » 21 month(s) ago, # ^ | ← Rev. 3 →   +5 My solution solves the queries offline.For each row x find the minimum row i, such that the interval [i..x] on some coloumn is non-decreasing.Then iterate through all the queries which end in x and if i < q[x].l , then the answer for the query q[x].order is "Yes" , else it's "No".Thus the complexity is O(n * m + k).Check my code for better understanding.
 » 21 month(s) ago, # | ← Rev. 3 →   -16 About problem E. Many people thought why greedy solution works. The answer is simple: tests are weak.I wrote my greedy by sorting on bi in non increasing order and ai in non decreasing and failed pretest 4. Then I changed the order on ai to be non increasing too and it passed. I was angry that I did not notice that during the contest. Here is the submission: http://codeforces.com/contest/777/submission/24979922I did not notice that property, as it does not work. Here is the counter example, where sorting by ai in non decreasing order gives a better result: 2 2 2 3 1 2 3 The answer is 6, but my program returns 3. It is a pity that these tests were so weak and so many incorrect solutions to the hardest task were accepted.
•  » » 21 month(s) ago, # ^ |   +1 This is an invalid input because bi must be greater than ai.
•  » » » 21 month(s) ago, # ^ | ← Rev. 2 →   +1 Right. In that case greedy works as you would be always able to cover all coverable ai, with bj.Edit. How to solve the task with ai <= bi?
•  » » » » 21 month(s) ago, # ^ |   +3 Note that if we place some ai = bi ring, we cannot stack any rings more on it (contradiction: bi >= b_(i+1) > ai = bi) So first we solve the problem with ai < bi rings, and process ai = bi rings later.
•  » » 21 month(s) ago, # ^ |   0 I think Greedy Works always :)I faced a nearly same problem as you24985372 WA on test #22.. Using >= in sorting.24985387 AC only removing that = sign :( But I don't know why... Shouldn't I sort in Non-Increasing Order?
•  » » » 21 month(s) ago, # ^ |   +1 The 'less than' operator should follow the strict weak ordering. So '>' is the right choice because it should return false with any two same arguments. See also: http://en.cppreference.com/w/cpp/concept/Compare
•  » » » » 21 month(s) ago, # ^ |   0 Got it .. Thanks :) :D
 » 21 month(s) ago, # |   0 My solution for problem E gave WA, but I can not understand what I did wrong. Here is my approach: Sort the rings with respect to 'b' in descending order. Now consider the rings in the sorted order. For the ith ring, get the maximum height achieved by i-1 rings with 'a' less than 'b' of the ith ring (used coordinate compression and segment tree for this). Add the above height to the height of the ith ring and store this value for the ith ring. Maximum achieved height by all rings after all of them have been processed is the answer. Link to the solution : http://codeforces.com/contest/777/submission/24974400
•  » » 21 month(s) ago, # ^ |   +3
•  » » » 21 month(s) ago, # ^ | ← Rev. 2 →   0 Thanks...but now I dont understand why Pretest 4 did not cause a problem for me. My solution failed on test 20.
•  » » » » 21 month(s) ago, # ^ |   0 I think because in that test a's are sorted initially in correct order
 » 21 month(s) ago, # | ← Rev. 10 →   0 UPDATE: Sorry...wrong thread...it should be under round 402http://codeforces.com/blog/entry/50658?#comment-346176