MDantas's blog

By MDantas, 6 years ago, ,

Hey Guys!

I'm the SRM 624's problem setter and I'm very glad to invite you all to participate. It's my first time as a topcoder problem setter, let's hope it's not the last :D

The contest is going to take part tomorrow (maybe today, it really depends on which part of the world you're right now): http://community.topcoder.com/tc?module=MatchDetails&rd=15857

Hope you guys have fun and enjoy it.

Wish you all good luck!

P.S: Let's discuss problems after the contest!

P.S2: Tomorrow is also the World Cup Opening, so we can discuss it here either! :D

• +87

 » 6 years ago, # |   +22 First time to know the writer of problems before SRM , Usually s/he login as a writer and we ask who is the writer after the end of round :) sometimes topcoder admins ask us Guess who is the writer I notice you are brazilian :) so today your country host SRM and World Cup :) GL & HF
 » 6 years ago, # |   +23 Nice. I hope you had not discussed any problem with me? Because I want to participate
•  » » 6 years ago, # ^ |   +15 All problems are brand new, so you can participate.
 » 6 years ago, # |   +27 I've heard that at topcoder it's strictly not recommended to announce your own authorship of the contest, that's why we usually don't know problemsetter until round ends. Won't they blame you in violating their rules?
•  » » 6 years ago, # ^ |   +30 Yes, I was told not to reveal the identity until the end of challenge phase in SRMs and TCO rounds. Does this changed now?btw, It's interesting to see a writer from Brazil while the World Cup is there. I guess the tasks will contain something related to the World Cup. Let's see if I'm right after the contest.
•  » » » 6 years ago, # ^ |   +43 No, this is not changed, but we haven't informed MDantas about that. This is noted, new problem writers will be better informed in future.
•  » » » 6 years ago, # ^ |   0 I guess the tasks will contain something related to the World Cup. maybe like this problem? ;)
•  » » » 6 years ago, # ^ |   +8 No problem about the world cup :(
•  » » » » 6 years ago, # ^ |   +32 Quiet, ongoing contest! :D
•  » » 6 years ago, # ^ |   +47 There's nothing on the TopCoder Writer Contract covering that possibility, at least I didn't see.
 » 6 years ago, # |   +4 How to solve 1000(Div2)?
•  » » 6 years ago, # ^ |   +3 Contest has not ended yet! Wait a little bit.
•  » » 6 years ago, # ^ |   0 Just calculate nim-value for all state's. Read about it here: http://en.wikipedia.org/wiki/Nim
•  » » » 6 years ago, # ^ |   +3 I solved it the same way, but I think there's a simplier solution. If someone solved it simplier, please tell your solution.
•  » » » » 6 years ago, # ^ |   0 ashka's solution: int winner_ashka(int N) { bool t = false; if (N == 1 || N == 35 || N == 15) t = true; int n = N%34; if (n == 5 || n == 9 || n == 21 || n == 29 || n == 25) t = true; if (t) return 2; return 1; } How?! o.O
 » 6 years ago, # |   +23 It was like CF div2 CDE. Almost the same 1000: 342E - Xenia and Tree
•  » » 6 years ago, # ^ |   +26 Yes, and it seems that changing module by 2 also radically changes everything in 500:) http://community.topcoder.com/stat?c=problem_statement&pm=10805Yet anyway, 1000 was hard enough only to be solved by the few, so I guess it is alright.
•  » » » 6 years ago, # ^ |   +13 I'm sure most top contestants know exactly how to solve it (BIT over HLD), it just takes time.
•  » » » » 6 years ago, # ^ |   +13 Agreed. It was more of a coding then a thinking task — yet difficult enough.
•  » » » » 6 years ago, # ^ |   +11 My didn't fit in time just a little bit. It could be optimized to , but I didn't make it.
•  » » » » » 6 years ago, # ^ |   0 I guess your solution is something like: - when a new node is painted blue, add it to a list (if we now have sqrt(Q) nodes in the list then recompute values for the whole tree in O(N) time and clear the list) - for a query: take the answer from the last tree "rebuilding" and then traverse the list of nodes which were recently painted blue, compute the LCA to each of them and add the distance to the answer of the current query.I implemented this approach but I was getting TLE on the example test cases 4 and 5 (and I only finalized it too close to the end of the coding phase to be able to optimize it in any way). After the coding phase and looking at tourist's solution (which is just what I described above), I realized that my TLE was coming from the recursive traversals of the tree : because of the way the parents were given, the nodes could be traversed simply in ascending/descending order (except for a initial DFS). After replacing the recursive traversals with simple "for" loops I got AC in the Practice room. Maybe the same thing happened to you? Or maybe you just used a value which was too large or too small for "sqrt(Q)"? I used 200 (and I saw in tourist's solution that he used 100).I waited until now to write this because I was unable to submit my solution in the Practice room yesterday and also earlier today (whenever I tried to compile my solution, it said that the request timed out).
•  » » » » 6 years ago, # ^ |   0 It can be solved in O(N * sqrt(N * log(N))) time, without any data structures.
•  » » » » » 6 years ago, # ^ |   +3 How do you solve it without using LCA?
•  » » » » » » 6 years ago, # ^ | ← Rev. 2 →   +8 Even with LCA (sparse table) you can solve it with O(NsqrtN), just SQRT-decomposition.
•  » » » » » » » 6 years ago, # ^ |   0 Not sure I understand your comment. What does "Even with LCA" mean? My point was that LCA is a data structure.
•  » » » » » » » » 6 years ago, # ^ |   0 Okay, I misunderstood you.
•  » » » » » » 6 years ago, # ^ |   0 Every queries perform DFS on a full tree. Also we can build a tree "stretched" on the next vertices and find distances between every pair of them in O(Q).
•  » » » » » » » 6 years ago, # ^ |   0 Nice usage of the fact that the problem is offline, thanks!
•  » » » » » » » » 6 years ago, # ^ |   0 ...which is just a disguised Aho-Hopcroft for processing LCA queries. =)
•  » » » » » » » » » 6 years ago, # ^ |   -8 I know only Tarjan's algo for answering M offline LCA queries in O(N + M). Is there any other approach?
•  » » » » » » » » » 6 years ago, # ^ |   0 I believe that's the same approach. Quite a lot of different names are used for it.
•  » » » » » » » » » 6 years ago, # ^ |   +8 Rubanenko, you forgot about the inverse Ackermann's function.
•  » » » » » » » » » 6 years ago, # ^ |   0 Do you remember that DSU has actually unproven complexity? There was an error in original proof.
•  » » » » » » » » » 6 years ago, # ^ |   -11 Who ever cares about Ackermann's inverse? :)
•  » » » » » » » » » 6 years ago, # ^ |   0 'Actually'? There is just a list of another articles that assumes original paper contained some mistakes. And some of these articles were wrong by themselves. So, I'd better not claim that the original complexity is 'unproven' or 'wrong'.In any case, there is a rather simple iterative logarithm upper bound, which is missing too.
•  » » » » » » 6 years ago, # ^ |   -17 Oh, well, without advanced data structures :)
•  » » » » » » 6 years ago, # ^ | ← Rev. 2 →   +3 Here is my solution. Answer to each query of type 2 is: depth[v] * number_of_blue_vertexes + sum_of_depths_of_blue_vertexes — 2 * sum_of_all_lca_from_v.Let's calc last sum. Denote v = p0, p1, p2 ... root = Pk the path from v to root. So for every pi we should add depth[pi] * (cnt[pi]-cnt[p_i+1]) to the sum. But depth[pi]=w_pi+w_p_i-1+...+w_p1. If we disclose brackets, regroup elements and simplify the expression, we get: sum = sum by all i from 1 to k of weight of edge from pi to its parent * cnt of blue elements in subtree of pi.So solution is this:1 type of query. inc all vertexes from v to root by 1.2 type. Calc the sum from v to root weighted with weight,of edges to parent.We can do that in n log^2n time with hld, or in n logn time with linkcut tree.
•  » » » » » 6 years ago, # ^ |   0 It can be solved in O(N * log(N)) without any data structures using divide-and-conquer on a tree, provided that you sort numbers between 1 and N in O(N)
•  » » » » 6 years ago, # ^ |   +5 The intended solution (in fact my solution) was O(N log N): - First pre-process the tree and divide it in its centers. - For each query of type update, traverse centers until you reach a center equals to query's node, just update its value and recursively update it's predecessors. - For each query of type get, traverse centers suming up for each subtree that doesn't contain the query's node its pre-calculated value, recursively go down until you reach the correct node and just return the result.As ivan came up with a different and very nice solution O(N sqrt N) we decided to let both of them get accepted.
•  » » » » » 6 years ago, # ^ |   0 I send NlogN using Link-Cut tree. But I don't think problem, which alows to solve quite easy, it you have prewritten structure is good.
•  » » » » » » 6 years ago, # ^ | ← Rev. 2 →   +8 If it allowed "quite easy" solution with pre-written structure, your score for this problem would be 700+ :)
•  » » » » » » » 6 years ago, # ^ |   -8 But with TC, 700+ means instant solution; it could've been easy as in the rest of the solution is easy to think up, but still takes a while to write.Countertroll!
•  » » » » » » » » 6 years ago, # ^ |   +3 Look at PavelKunyavskiy solution, the amount of code not related to link-cut-tree implementation is very small. And one must spend more than 20 minutes on problem to get 700 points for 1000-ptr.Actually, I also have a pre-written implementation of link-cut-tree, but I decided that I'll spend much more time on modifying it and debugging the solution than on coming up with some simpler idea.
•  » » » » » » » » » 6 years ago, # ^ |   -24 20 minutes isn't much...Sure, why not. As I said: countertroll — not a very serious response to another not very serious post :D
 » 6 years ago, # |   0 Today a new restrictions come: n <= 4000, n <= 2000 Max tests have given three successful challenges to me :)
 » 6 years ago, # |   +30 Modulo on my template int MOD = 1000000007; Modulo on the main code (the correct one) LL mod = 1000000009; Modulo on calculation if (ways[v] >= MOD) ways[v]-=MOD; gonna remove modulo from my template :( and perhaps my shift key from my keyboard...
•  » » 6 years ago, # ^ |   -16 Good luck with if (A && B) :P
•  » » 6 years ago, # ^ |   0 Me too. That was not fun!
•  » » 6 years ago, # ^ |   -8 precisely the reason why i removed #define MOD 1000000007 from my template! :D
•  » » 6 years ago, # ^ |   +8 450pt of Petr also get successful challenge due to the same problem
 » 6 years ago, # |   +18 The pretests was very very weak :(P/s: Can anyone tell me how to enter a 2000-element vector to challenge?
•  » » 6 years ago, # ^ |   -8 Input "1,2,3,4,5,..." in the text field and press "++"
•  » » 6 years ago, # ^ |   -8 There's "++": "enter comma delimited array". You can make one with 2000 elements by making one with 2 elements, and (copy-pasting 9x) 3x. This is what I found out today :D
•  » » » 6 years ago, # ^ |   -8 {1,2,3,4,.....,4000} then press {}
•  » » 6 years ago, # ^ |   -8
•  » » 6 years ago, # ^ |   -8 {1,2,3,4,5,...,4000} and press {}
 » 6 years ago, # |   +24 What is stack size for GCC on TopCoder? I think that I've got stack overflow in my 1000 on the server, is that possible?
•  » » 6 years ago, # ^ |   +8 I think the stack size is standard (2-4 MB), unlike Codeforces.
•  » » 6 years ago, # ^ |   +8 Seems that the stack limit recently dropped. When memory limit was 64 mebibytes, stack limit for C++ was about the same. Now, it is more like 8 mebibytes, don't know exactly.
•  » » 6 years ago, # ^ |   0 I also have this feeling about my 1000.
 » 6 years ago, # | ← Rev. 2 →   +16 Just when my rating is 2182 and I expect to be red tonight, I got MOD problem :'(((((
•  » » 6 years ago, # ^ |   -8 Sorry for that, we didn't even noticed that sample cases were not covering MOD overflow.
•  » » » 6 years ago, # ^ |   -10 Apology accepted. But still you owe me huge amount of rating.... :'(
 » 6 years ago, # |   +2 looks like i will go down from yellow to blue today. maybe this is a sign that i should stop supporting Brazil and support Italy or France for the World Cup! :P
•  » » 6 years ago, # ^ | ← Rev. 2 →   +4 You are Juan Mata, you should support Spain then :P(for non-football fan : Juan Mata is a spanish football player)
•  » » » 6 years ago, # ^ |   0 unfortunately though, i don't think Mata will start tomorrow's match against Holland :(
•  » » 6 years ago, # ^ |   0 I want to support Germany (white), so I should register a new account and make it unrated :(P/s: All TC admins support Netherlands :))
 » 6 years ago, # |   -7 System testing is so slow =(
•  » » 6 years ago, # ^ |   +5 N<=4000, n<=2000, n<=100000.
•  » » 6 years ago, # ^ |   +1 not even 50% finished :'(
•  » » 6 years ago, # ^ |   0 Yeah, seems like we're up for a 2-hour systest...
•  » » 6 years ago, # ^ |   0 I wonder why they don't show current standings? Some time ago we could see live systests, didn't we?
•  » » » 6 years ago, # ^ |   +17 Nope, the results are always being opened room by room after system testing is over.
•  » » » » 6 years ago, # ^ |   0 Thanks) Seems I thought this room by room showing is systest itself >.<
•  » » 6 years ago, # ^ |   0 perhaps the server is too busy preparing for the World Cup :D
 » 6 years ago, # | ← Rev. 3 →   +1 Wanted to ask — why problemsetters in Topcoder use "generating functions" for inputs? I can understand that happening in Codeforces (where reading from file can cost too much in some languages) or in GCJ, where time required to download inputs is deducted from total time given for one attempt.I am not so sure about SRMs. Parameters are passed to the function. If you pass then by reference, there is no time overhead. I think all languages at Topcoder can do passing by reference (at least I am sure about C++ and Python, should be the same for Java). Also you had this statement saying that "the way it was generated doesn't have any relation to the way it should be solved", which presumes that it was just a technical step.So what prevents from passing input as it is, without those generating functions?
•  » » 6 years ago, # ^ |   +6 TopCoder's system. If you have an input of length more than ~2000, it crashes for some reason.
•  » » » 6 years ago, # ^ | ← Rev. 5 →   +14 Thanks!Maybe some kind of limitation on how much database memory you can spend for holding testcases for specific problem. I forgot that they also have to keep all testcases indefinitely (potentially), so they probably don't want to have hundreds of 50Mb testcases for each problem.UPDATE1: On another thought — Topcoder could keep this "generating function" in database and create input whenever it is needed for testing, so this is non-issue. The only issue is that it is not supported by current platform. But I think it is definitely good feature request.UPDATE2: Generally I can see pattern posts with bad ideas get lots of minuses and posts about somebody's struggles with problems if they don't end up in good question or in good answer get lots of minuses. There is exemption for red rated though. But I don't understand minuses for this question — whoever wants to put another minus please tell why do you think that this is bad idea.
•  » » 6 years ago, # ^ |   +12 One of the main reasons I learned when I was writing Div1-Hard is that if TopCoder allowed huge inputs, it would not be possible for someone to challenge as it's not that easy and fast to just copy and paste a huge data. If topcoder had some way to send a file or even a generator, then it would be fine to have problems with huge input. Another reason is that topcoder problem setter plataform really crashes with huge inputs or outputs, that's the reason we just asked for you to return the bitwise XOR sum of all answers instead of just returning an array. I don't know whether this is true or not, but someone said that TopCoder is building a new web plataform similar to Codeforces.