The Vanilla Method Let's take the given problem: We have some sets as U = {S1,S2,S3....Sn} where U is the "container" set. Initially each set contains a single element. After each operation each set will contain some numbers. We define the cost of a set as the number of unique elements in the set. For each query, we merge two unmerged set and then report the sum of cost of all the sets. The most brute force approach is for each query, add all numbers in one of the sets and put them in the other set. This will take approximately O(nlogn) time per merge operation and since there can be about O(N) mergings (because after atmost N mergings there will be only 1 set left) this will take time proportional to O(n^2logn) time. For the report, part, we just return the sum of the sizes of the set. This part is O(1) as we only have to check the size of the new merged set as the sizes of the other sets haven't changed. This is obviously a poor algorithm for a seem...
Segment Tree Beats Disclaimer : This post is based on a recent post made by jiry_2 on codeforces. Before I begin, a clear understanding of segment tree and lazy propagation is required. If you don't know those, I would recommend you to go search it up online and read it thoroughly, before coming back. With that out of the way, here goes... Hey wait wait wait. Hold on. Just to clarify, now that you have read it, in case you are confused with what I call terminal nodes in a segment tree update/query, it's basically the node that is completely inside the update range, the one where we generally end our search in a segment tree. I say generally.. well.. you will see :). Anyway without further ado... A simple problem So the first problem I want to address, and it is fairly easy, is supporting two operations on a range: Range minimize (for each i in range, make it min(i, update_value) ) point query Solution : This is just a variant of the n...
Regional Mathematics Olympiad The Regional Mathematics Olympiad (RMO) is the second stage in the selection for the selection of the Indian team to the IMO, the first being the pre-RMO. It is one of the tougher olympiads conducted across India, wherein only about 300 students are selected to sit for the Indian National Mathematics Olympiad(INMO). The main thing that makes RMO tough, at least for the common students, is twofolds -- firstly, the syllebus is quite a bit different than the normal class X or XI curriculum that is followed in schools, especially in areas like combinatorics and number theory, the latter being a topic that is scarcely touched upon. Secondly, in topics that are known to us, like geometry, the level of questions, even if they don't require advanced theorems and results, they need a level of creativity that cannot be mastered overnight. From hereon I will say what I did to clear it last year.. when I was studying in class IX. Firstly, I focused heavil...
Comments
Post a Comment