Codeforces problem solving (sports programming), 2/2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
and we are back live my machine or maybe my internet connection bro I'm not sure what happened and yeah we're back I'm checking in situ over YouTube and twitch work I don't see stream on YouTube so maybe something doesn't work for you - well it does ok internet is shaken I'm not sure I think that the restroom chat broke I couldn't access this website that is my website to restraint above twitch and YouTube okay I'm so - just before it stopped um I'm not sure what that sound was but back the problems what I was what was I saying I know somebody asked me about about greedy problems how to probe greedy and then I usually recommend this video of Al Gore's life that has several proofs step by step I'm putting that in the chat now okay Hindu mythology around 560 is done and we'll move to the next contest by the way it's funny that it broke after I finished the contest what is cold because contest wasn't broke I didn't want to hit that okay I think I don't know any problem from this education around so I can honestly participate let's put that was 1305 start in 10 seconds title what is it add those 65 and 65 tie okay and we're back solving problems my question goes as fast sorry after the contest you must ask beef between two contests their phone number is sequence of exactly 11 dearest were the first DVD site you can delete any character you want to make as valid phone number the first number should be 8 and then there should be got 10 more digits so I will I think I will remove characters from the end till I hit a night and then some characters from the end at first from the start till till I hit the till I hit 8 then from the end I was here let's put everything that was what 560 cf 560 move everything to that now make a dough 65 and copy that templates this is what CF templates here but let's change in these templates let's remove that and now we can solve problems okay I can solve that we've seen it will be easier for each test case reach the string and we should print yes or no so I actually don't have to remove those characters I will just find the first eight while I small down as length and line and as of is not eight plus plus I and now I need some formula like there should be ten more characters to the right then puts as of as length - i greater equal may be 11 then yes otherwise no this is distance from the first eight to the right and now let's think about it as if I put here free then if I is there then I have exactly free and this is found this is number of size way so I think it's okay eleven is here this should be correct no yes oh it's the other way round otherwise print no our first is and assault as length.you sequel and and like that I could use and yes no at the 65 i cpp here we go by doing short if you want help with a problem also I need a source of that problem I don't want to help with problems from ongoing contests problem be interactive problem remember to flush output blah blah blah Dreier guest some array a consisting of six integrals the guest they didn't guess they chose there are six special numbers and each of these numbers occurs in exactly ones not know anything about the order but you are out to ask up to four queries in each query you may just do indices and you'll get the value of the product in return can you guess the array there's some order of those numbers and possibly there there are exact values matter mmm I have those six I can ask about maybe first which second sex first with far 50:56 but then I don't distinguish which one is which even if from product I can figure out their values and the farquar will not be enough to figure out all six values that which one is which what about asking first with second then first we firt first with far first with five would that be enough I think it's enough to get that first value and also because of that we know other values and we'll know this one as well now let's try that how do we ask yes I put one toe maybe far for everything from two to five print one and I flash and read the answer response of size or maybe answer of size six seven and with I will index from one to six answer of I is is what is whatever I read here so scan [Music] for a moment just for the sake of testing I will here put hidden permutation maybe 8 for 23 42 15 16 and instead of here reading I would say answer of I is hidden out of one times hidden of I and here that put fake value and now values are number 2 1 4 6 and I will be able to test it quickly to see if I figure out if my program figures out this hidden sequence I don't need to interact with it what would take a lot of time then for int X in 4 8 15 16 23 42 let's let say this is a cost vector values is that for each X in values I want to check it this is possible answer of 1 we have those products I'll say Ark is true for everything from 1 from 2 to 5 if answer of I that product model X is not 0 then arc is false if arc then answer of 1 is X there's that case that they don't like the fact that far eight and 16 are divisors of each other so maybe I will have a mistake because of that we'll figure that in a moment this problem looks harder than average did to be I don't get that answer minus X now for each thing from two to five answer of I is that now it's a product and divided by the self out and answer of 6 is the remaining thing so I was how to find the remaining thing I would say for everything up to six answer of 6 plus equal to find the sum of values then subtract those that you already found this way I have one last remaining value for everything in answer trained and certified and I don't need to flag because terminating in program does that anyway let's run it I got eight for 23 42 15 16 call what if I change the order for indict for I'd call but then what if 15 is at the end what if powers of 2 are at the beginning correct and here 16 and far okay looks fine so let's remove that computing hit the project myself and I will read the answer the format looks fine I think I put exclamation mark I do and submit I think the proof of correctness if it's correct is that among those numbers from 2 to 5 there must be at least one odd number there is at least one odd number here because 2315 one of those must be here and because of that I learned the product of power of 2 and that odd number so I think this is why we can't make a mistake here between different values what does the chart say not enough not it is like apparently T's that was surprisingly heart in my appeal problem see title is vector initialize to 0 by default you didn't set yes by default vector is set to 0 there are any and users in M groups usually some user extra sieve the news from some source then sense to friends for each user X you have to determine what is the number of users that will know the new zphone initially this problem I've read considering it for YouTube and it goes like that this is C black place this is problem see there are some clicks one click then some other one and they can have common vertices you need to figure out connected components vertices from which you can get to each other and how to do it we are given those cliffs that if we gather all the edges there will be up to n square of address and in Staubach and is 500,000 that's not a good idea but if if you run DFS or BFS whatever and you get to a vertex that is inside some clique then we can go for other vertices in that click mark DeMoss visited and forget about this clique anymore you don't need to explicitly star edges mmm I think we can go for actually two solutions for this problem mmm maybe one I think one is enough I will try to not explicitly go through edges and I will mention some other solution and then the groups and what we need to find every number of which connected components it is in join it find an Union I can use find an Union Max and Miss dot this is 500,000 plus 5 then I will use visited for each group the vector of inte group of logs and for every grow read the number of elements there the number of vertices in that group in the clique and then read the values read the vertex X group of I push back X and additionally his groups of X push back I for each vertex I know in which group which groups he belongs to these groups of marks since I'm not doing any extra loops just I read the input here the complexity of this part is equal to the size of the input I can't do better than that now for everything from 1 to N if it's not visited then run right along DFS the FS of a or maybe bf bf s would be faster but let's try with DFS the FS of a a start not visited to make sure I run everything correctly visited of a stroll no-brainer way of solving B is to test all 6 factorial permutations but you need to ask good queries still with my solution I would need to some queries maybe aren't enough to distinguish all 6 factorial possibilities and now is the normal in DFS we iterate over edges in something here I will iterate over his groups of I and if not considered already not done of dream not to repeat the same thing for every vertex in this road so I also have done of remarks and that says whoever this group is already considered then none of this true for everything in group of G d/f sob okay and now as an extra let me gather vertices here I will put gather push back a and then after I run DFS for each vertex X in gather answer of X is gather size this is the size of this connected component and gather clear not to remember that connected component for next vertices for everything from 1 to n vertices are numbered from 1 to N print serve I the size of the connected component with vertex I I need to turn that here let's check assertion not visited blah blah blah if I go to the F first order B then if not visited of B and then do that otherwise arm finding and thanks to my assert I immediately saw what is wrong otherwise I would get some infinitely far far one four four foot looks fun I said I would mention one more solution and that is every trick can be compressed a little bit when you have a click with vertices ABCD then instead of putting called quadratically many edges then just side that this denotes I just a b AC ad and you're good to go the number of edges now produced from the input will be linear equal to the size of the input and you can run standard DFS you could also run standard DFS and I think that would be easier than what I did I prefer Marvel my version I think it's more fun problem D I remember that I also opened this problem to consider that for YouTube but I thought this is too too long to read why don't you use lambda in this shorter so why should I use out of here if this is what you mean mmm C is shorter with DSU okay also worries that's fine mmm I wanted to do DFS C copy and often dCPP bracket sequence bracket sequence has opening and closing brackets it's regular obvious if it is possible to obtain correct arithmetic expression by certain characters plus and one empty one this one this one are obvious I guess they just mean the how is it called correct bracket sequences function inside the main but I sometimes use lambdas if that's your question Mustapha but why would I hear the first words convenient if something can be global and I have just one function then why should I put everything in main it would be harder to read create functions if they are not short we can define nesting depth of our BS locks in number of brackets of part such that second paralyze inside the first one and so on I think there's call interpretation of what they're saying if you treat every opening bracket by the way this is d if every opening bracket is plus one and closing bracket is minus one then every the correct sequence can be treated as a graph I mean function that goes plus 1 plus 1 minus 1 plus 1 plus 1 minus 1 minus 1 minus 1 and apparently I put too many in brackets yet this one is unnecessary the start and and should be on the same level and we should never go below this zero level and now what they define as depth is here the height of the draw this this is height H the maximum perfect some feature it draws us plus and minus one you're given RBS of even length we should color each bracket of us into one of two colors or red or blue consider red brackets should form RBS and blue bracket should form RBS mean you should minimize the maximum of that of Knapp sting depth so you should make them flat minimize the Maxine yep okay hello to Egypt you have so many messages in cut forces yes but they are very very oughtn't it's hard for me to scroll to those messages okay we should split those that sequence of plus and minus ones to two sequences to minimize their heights if we need to put some if we need to find some answer that is up to n and we say kind of can we minimize that so can we get this or lower with something or that this often means binary search over the answer I will consider that right so maybe binary search over the answer maybe some greedy maybe dynamic programming indices what this problem looks like let's put that to direct okay what about something grid I have the first plus one so I put it to one of the two strings then I have the next plus one let me put it to the next to the other strings like I basically break this drawing into two then I have minus one I will put it to whichever then plus one I will put it to the one that wouldn't lead to bigger height so always plus one put to the drawing where you are lower right now some this greedy approach because if you put it to higher one if here we already we already have two it's bad to add one more plus one here I think we don't gain anything by that it's better to put it here the neck strap as well something like that so this is the situation after this moment and then minus one minus one minus one if here all the time because this is a correct sequence and although all the prefix were non-negative then also in our new situation here if the traffic's was P then here if we have prefixes a and B like the height on which we are right now then we know that a plus B is equal to P what means we will never get problems with putting a minus one we will never get below zero because if P was positive so it could go down by minus 1 then 1 of A or B must be positive so always we can put minus 1 to 1 of those two mmm we need to reconstruct we need to say for each one if it goes to left or right 0 1 yeah I think this should be easy read and read - drink max and is 200,000 plus 5 AF max now I start to Sam's 1 and talk for everything that is in the input if maybe let's make this as an array int graph of 2 is 0 0 now if I of I is opening bracket then I need to put it to smaller of the values interval is 0 then if smaller if pref of 1 is greater than smaller than pref of 0 who is 1 and now else so if I of I is the closing bracket if the other condition and print Oh graph of ho plus equal and now AF is opening bracket if he has done plus 1 otherwise minus 1 new line such a greedy approach and what is and we don't return here zero one that's incorrect mmm that's for sure incorrect what happens if opening brackets then do that I wanted here an opposite condition intended so just like that no we're good to go zero zero that's fine both characters 2 1 think 0 1 0 and this is the same as here this is more complicated but let's see at least if it makes sense opening bracket here and closing there and the other will be quite flat opening open closing opening I think it's fine the proof of this greedy approach would be it doesn't hurt us to put plus 1 to that drawing that is like flatter it only helps because it leads to smaller answer to smaller a maximum height I guess you put extra plus 1 in drawing [Music] did I like that doesn't matter maybe I make a mistake maybe I made a mistake looks more or less fine now the next problem this will be what I arrange deleting now I hope we are getting 2 free interesting questions they think it's possible to reach 2,000 rating I think you can guess the answer is it possible to reach 2,000 rating yes there are some people who reached that rating in three months training on average depends on your current level love's background and so on yes if you if you are I don't know 1800 level then you can reach 2,000 in one month you are given an array consisting of an integers AI and some integer X function f are erases all values in this interval between l and r your task is to calculate the number of pairs that that and r is sorted in non decreasing order FDR is also called sorted let's try visualizing that because it's harder to do anything here with just numbers if this is I this is AI then for every I will have some value and choosing some Island are in this problem would denote maybe I can do that with red would denote removing some stripe and this is L this is our our the question is in how many ways we can choose and our such that what remains what is not removed is sorted increasingly actually non decreasing during actual comes as the user on tablet of course not pen and paper are much faster it's quite inconvenient for me to use drawing tablet but it's for the sake of explaining something to people need okay now how to count that there could be some in particular I need to it's it take me time some time to change the color there could be some points there I would like to know how much far I can how how far high I can get so how big L should be so that those values points up to L are increasing so points below some level then I will do the same thing here from the top and I will need to in some way combine that lets say I figure out that up to some level the values are increasing this is some L actually non-decreasing there could be ties then there is something above that let's put the drawing lower up to some level and the values are increasing so L can be anything like that or lower not greater because then it would stop being increasing and then from some value up it's also increasing here maybe there is a point there maybe there's a point there for sure this area in between must be removed because I found the maximum possible L the minimum possible R and I need to figure out how to combine them because not all else and ours match each other here if we take the house stripe this one and this one this will not be increasing because the last point on on the bottom can be to the right from this one what looks like some two pointers some binary search for each L I need to figure out what is the smallest possible R for this L this one I think we must here start from this position to the right and I need to figure out that limit for our limits are up to 1 billion up to 1 million let's start finding that maybe let's think for one more minute before implementing I will find that best and are if there is nothing between them no maybe the whole sequence is already increasing then I print some formula like the number of all possible intervals and that's it we're done otherwise I find that best and are I create some to our eyes that I will have to merge with each other our eyes that denote here for the top for each are how much the right I am so I think like that by the way we could rotate the whole thing by 90 degrees or just maybe swap the coordinates then the question becomes in how many ways we can remove some stripe vertical stripe such that the remaining things are increasing maybe that would be easier to do but the values in the input that are not necessarily distinct that makes things slightly harder so it's with or maybe maybe it's good to switch to that interpretation I rotate I flip everything I meaning I swap accent why over off every point index is what we value then that will be I'm removing vertical stripe and this is our one 4x still I need to live increasing sequence like I think I will not do that I guess I will be doing something equivalent anyway let's read the input and read the sequence I maybe we need to remember something extra let's put these to the left what do I want to do for every height like for every value do something I think I will be doing something equivalent to swapping the coordinate index with value because now for every level I want to find all the indices that have point on that level I will here put minus minus AFI now values are from 0 from X minus 1 and I will find leftmost and rightmost for every value small and big small for X this is by default infinity and big X minus 1 infinity is something very big 1 billion plus 5 then small of AF I is minimum of small of a of I and I and big FA of is the same thing just with maximum I think that now for every level I found that leftmost and rightmost index that have that has that value those in between are anyway in between now I want to do what I want to maybe first already increasing his throat without even removing everything if not AF I small equal I have I plus 1 then already the increasing is false if already increasing then put some formula here it should be I think x times X plus 1 over 2 this should be the norm of interval set C for X equal to 1 this is 1 for X equal to 2 this is 3 1 1 1 2 2 2 that's fine and now special case is tracked and harder part is how big L can be is 0 in big so far is big of L while L plus 1 is still smaller than X I don't need to check that because I know that I will stop before the end of sequence because I checked for all increasing sequence so we will even first while big salt far smaller than small of L plus one week so far smacks of itself and big of L plus 1 and plus plus L this means that going from L equal to 0 when I have some points already then big so far is that rightmost point the last one and for new level for L plus 1 there are some points here on that level I check small is the first of them I check if it's on the right from the previous value it can be on the same level because there are no two points on the same level there are no two points with the same index I for every eye we have just one value and then big so far becomes this one it's my maximize because maybe big so far will be minus one because this is how I ensured initialize then the same thing from the top R is n minus 1 small so far is small of our while small so far greater than big of R minus 1 this is symmetric to what we've did from the bottle small so far it's me itself and small of R minus 1 minus minus R then let's print and our nose limits here we have zero and one here we have out-of-bounds index six what contender blah blah blah what is wrong our should be X minus one not n minus 1 1 & 3 & 0 & 1 let's quickly see we have here two three one and then indeed then our should be two value 2 and up our sorted but I decreased everything by one so this is correct and this also correct only one can be in the bottom part and here only this is sorted threes and fours aren't so our should be this minus 1 3 correct and to wound and toad and free L should be 2 minus 1 which is 1 cool then let's also check if it works for increasing sequence what about this for 2 1 1 2 2 3 okay I think that's fine values can be 1 1 or 2 2 or 1 2 but if I put 2 2 1 1 there's some else now let's gather as we go here let's gather some values what I call I will call them 1 & 2 & for each level that we visit let's look back at the drawing for each level we can forget about these I will know for the for this L up to some level what is the rightmost value for this L what is the rightmost value and so on this rightmost is big so far I will push that one push back big so far also before the first one one push back big salt five then to push back small so far the same here to push back small so far let's print them one and let's print - I think I'm looking for the number of such pairs that the value from one is on the left from the value into actually because we allow allant are to be 0 and n minus 1 that would leave us with with something empty that is even before that so I will say here 1 push back big so far even before L equal to 0 is minus infinity minus 1 similarly here to push back infinity now I think I'm looking for pairs such that L gives us some left some right its rightmost point from the bottom is on the left from the left most point in the upper part if we have some points at the bottom and some points at the top then this one should be under left from this one then this L with these are are fine so broad force would be answer is zero for everything some big I in one for everything in tow if I smaller than B plus plus answer but for now it's quadratic would see if it works on samples four and six works now I need to do it faster those vectors are all already sorted and I can do binary search or two pointers for everything here I need some prefix of that so for each element in the first vector some prefix or the next one is greater than me so I will say I will use two pointers up to is - sighs - one for each element in one while up two is greater equals zero and two of up to if that last element is smaller than me because I want it to be bigger than me now what I - - up to now all elements up to up to are good a surplus equal up to plus one this is the number of elements up to this value now it should be linear which two pointers looks correct let's submit that was problem e from educational around 65 we have two more problems scholar queries that looks by the number of accepted submissions doable and then G that is quite heartless Ronnie context 64 accepted we move the problem F scholar queries changed title you're given an array all values are pairwise distinct the defined function as follows so we short we define shorter RI where bi is I I plus L minus 1 looks like just a shift of sort are IB increasing order result is of the function is that calculate this sum over everything in contest also do we wait for verdict before solving next question perfectly I shouldn't sometimes if I'm very worried about the correctness here I want to be done with one problem before starting the next one because this is a stream and later people might want to just track just one problem let's try to understand what happens this is f we have some sequence I let's look at the one from the sample five two four seven then are we given L okay so we are given some Island are okay and are let's say also there's 20 here says that this is subsequent this is sequence B then we start it in increasing order actually here it's already sorted then the result is some items first one and so on so this will be x one one times this two times that three times that but only after sorting if there was two four two seven four still we will still swap and then put multiplayers we need to calculate the sum over all the intervals when we have a big sum often I just count for each element how many times it will be added to the sub with what multiplayers let's try to figure that out we have some size seven here it will be put to some with multiplier times one in those intervals where this is the smallest number if there is eight here and turn here then in this interval in this interval this interval if there is also eleven here then in those seven will be with multiplayer one but then if there are six Darr then all intervals that contain the six as well will be put will have multiplier one I would say that seven gets for each smaller elements that is with this seven there is extra plus seven to the answer so the fact that this seven this six is here this one it adds multiple it increases multiplier of seven in all intervals that contain both the six and seven so all intervals that start somewhere here and and somewhere here from seven to the right all of those will have both six and seven and this causes extra plus seven to the answer then what I will need here let's focus on those Paris eyes maybe not a X smaller than Y such that X is on the left from Y in our example why was 7x was six then [Music] or maybe it's better to talk about illnesses I'm focusing on a smaller than AJ where I smaller high is smaller than J then assuming that I number everything from one to n such a pair should add to the answer I think I the number of starts up to I of interval times and minus J plus 1 the number of ends times a of J let's change the color if this was I this is J for all intervals that start here and end here the number of possible starts here is I the number of possible ends here is n minus J plus 1 I have extra multiplier plus 14.7 this is why I get that to the answer and for fixed J the second part everything here is fixed for joy and I need to find the sum over ice on the left for joy I need the sum over indices I on the left where value a is smaller and I will try to do that with some segment tree okay first I will read the input and then I will think what exactly I need to do and read and and plus one that's number from 0 to n minus 1 the input is here also there is model where is I need to forever J find the sum over eyes that on the left then I will repeat the process I think I will do the phone repeat is zero Apatow classless repeat solve and then reverse I begin I am this will be total answer at the end I will put the answer printed it this is integer just taken model I mean this is interesting then there is solve that will increase answer maybe I will pass here and you can say and and is a size do you sketch was during contest no I said pen and paper Dragon Con computer is very slow and it's inefficient and also during a contest I don't think out loud and just think in my mind it's faster mmm plus I can use some simplifications because it's important I understand that but not everybody okay I will for every index I need to find the sum of integers on the Left that are that have smaller values for this reason I will go through numbers from small to big ones so I will say the following create a vector of pairs just something let's call that B for everything B implies back so a pen that are a Fi and I and salt now for every pair in B P is index not this is value and index I tried this way from small to big values so I take P second this is index and I know first that this is smallest value and so on up there I'm done with some small values for each of them I will put in segment 3 its index and when I have new J I take the sum from some prefix in that segment 3 I've already put indices for smaller values so in segment 3 advice that are there are only those coming from smaller values let's create segments 3 here this one while miss more than 10 B times e : three of two times B this is my implementation of segment three and now then this is some power of two that isn't smaller than N and now first I need some up to the sum over things on the Left L is 0 r is R is I minus 1 if L is small equal up then I need to take some from the tree a called power of 2 R plus equal power of 2 sum is 0 and we create a function but I call that old self that takes a in V and it does the following shorter version will be a sequel a plus B modulo mode but model operator is slow it's better to avoid it and for addition you can just add and see if you over if you are over model then subtract this is equivalent to saying a plus B model model Sam plus equal 3 of L is different than power that I'm not explaining that because there are plenty of ways to implement segment 3 small R minus 1 if this is even some pasta country of L plus 1 R is odd in the older think and divided by 2 R divided by 2 I didn't need that I wanted to say add self let me copy that here it should be hard it should be hella + 1 + R minus 1 okay and now for everything from v+ i up to 1 on the path to the root of a segment 3 outs of 3 of X and this index I and actually because I number from 0 to n minus 1 here I said I need the sum over I if I tur it from what if I number from 1 to this is why here I put plus 1 and then answer is equal 1/3 plus long long some times a fi times now this thing but again we need to change it by 1 I think now it will be n minus 1 and minus pi this is the number of possible ends of interval from I to the right and this module mod and here I need model mode as well otherwise this would overflow let's try that I think I will still need to add something to the answer 83 and and some I think the issue is even if I put a sequence of just size one with value five the answer is zero I added everything because of those smaller values but as an extra every value in interval is counted at least once anyway so I will say for everything I'm sorry our surplus a of I times I plus one times n minus I naught and here again not to overflow long long this is the number of intervals that contain index I because in each of them I have I gets multiplier one already and now now the answers are correct for samples at least submit F I I knew how many times each number will be added and how many times it will be added because of smaller numbers that are also in the same interval and they increase its multiplier by one like seven instead of being added to the answer with multiplier one it will be added with times two because there is one extra smaller number in the center F is done how good am i doing not so bad and three that is apparently hard problem only two people so far to solve it so I'm not actually sure I will be able to sometimes the last problem in educational contests is hard we got bored and decided to take our own guess at how would inception production go the budget for Hume had been terribly long by the way inception is a good movie watch it if you haven't the Earth's in we remembered was the one that features the whole city burning them to itself the city is now represented as a number line infinite to make it easier of course that's a very long statement and I don't like the drawings looks like some geometry there n buildings on the line in building is a square one times one numbered from 1 to n it will think we know its position AI the distance between any two neighboring buildings doesn't exceed some value D [Music] curvature of the band is also really hard to simulate that the band had some integer current X let's remember that we bent at integer coordinate before front with the following Calgon take the Ray from X to plus infinity and all the beaming sweater on this restart turning the Ray and the building's counterclockwise when something touches another building are another part of the line you have to stop binding there now I think left is to decide what interurban take axis the best to start bending around we've already chosen an km candidates there are some candidates for where to bend and we should find that best angle let's look at this example and try to understand I will try to understand the statement at all I hope I do so we had that change to black we had that one square and then we are went to the right and here we bent previously we had a long line here with one square and other square then we start bending and eventually that line will be there with squares here and even further plus sometimes two buildings will meet each other mmm first example the burnt position - this is the answer a X is the angle by which we bent right winters in the furnace 30s now this is the final angle here this one we want to compute this so we kind of minimize that first it's 180 and then we closed it so here we can't burnt at all because their buildings touch each other okay there's that maximum distance I mean the number of queries will be 200,000 is there a limit for ai ai ai will be up to n times D I guess we have some buildings each room is a square of size 1 times 1 and then we bend at some point and we wonder when will some buildings meet or when buildings will meet a lie [Music] every point will have a line along with a language it will go like a circle or half circle that's the note that we and maybe it's enough just to have each of corners of buildings tools to see what path it has and when it crosses something notice they said the distance between two consecutive neighbor neighboring buildings is up to 7,000 I don't know how to use it maybe it's good maybe it's important in the precision of a probe problem maybe we need to intersect circles with squares or just with lines which is quite easy [Music] if there is distance to here and distance to here then this point blue one will be moved exactly to this one and this is the moment when we stop in heart geometry / rotation problems sometimes it's even good to take paper scissors cut something out and just move stuff around here if you have internet connection maybe it's good to go to some geometry visualization program and experiment there there is like geogebra I'm not sure about the name there are stuff that can do those things like rotations I don't know how to use it well maybe we don't need to deal with some intersections and it just about a point moving to position of another point this one here this one here what if there is nothing on the left like if there is a line you wouldn't see that if there is a line here is a square and we bent according to this line then we stop when I guess this point reaches some point there and then the answer will be this angle hmm the only things that can collide with each other the only two buildings that can collide with each other are those that are at similar distance from the bending point your bending point is here have one square and then here's something with different distance from the bending point then they will not collide at all I think because they will I think first this point will hit the ground later this point would hit this one but this is exactly the moment when this comes here with this traditional trajectory it doesn't matter anyway I think we can care only about those that are within the same distance and when do they meet or what happens when they meet when that this point will collide with this one so all this angle will be like removed this will be the belt and the remaining angle is this time plus that two times the angle I want to say that from the bending point I'm looking for the same time locking so I need to find the closest block the the smallest distance that there is a block to the left and to the right within the same distance exactly at that distance what sounds like f-15 but I think it's harder than the 50 maybe we need to figure out this condition about the distance of 7,000 my idea is that if so there must be a less band bending point is somewhere and all the buildings are far away in just on one side then this is trivial let's say but if there are buildings on both sides of the bending point then there are within distance at most 7,000 and both of them will eventually meet the ground and I think before that happens buildings that are very far away do not matter at all their bending point some positions if we have a block here even if there is nothing on the other side then it will meet it will meet some point on the ground so we will stop and that happens before oh you don't see the drawing they can scroll like a screw good mmm and if there is a lock far away here and block far away there that are within the same distance from X so so that are now completely blue then they do not matter anymore Thank You Connor for nice words maybe dalgaard should be look for two blocks that are with distance a distance at most I don't know 20,000 that are at the same distance from me and then stop looking anymore because that will not matter the complexity will be the number of queries times around 20,000 that would be too much but I can use bit sets mmm that should be fast enough plus we'll need some formulas how do people set such questions respect for them this one was inspired I guess by the moon when you look at this picture you can think like when will buildings collapse if you put them closer and curves now let's figure out the formulas if building meets a ground and let's say building is here if it meets a grant I think it's with this point so the final I can think then that the left line moves it will be here at the end instead of moving at the right one and the angle is here I can say that this is as are casinos of one divided by square root like this distance this one this is square root of 2 square plus 1 square where 2 is that distance from the bending point to the square and then what if there are there is a bending point and there are two squares with with at the same distance then those two points will will meet so the answer is the same just times two because those NATO's to me we meet so we'll have this plus that the sum of those two angles okay and the remaining part will be to figure out to figure out how to use big sets exactly let's read ain't that is dCPP constantly adjusting coordinates of left corners of corresponding buildings and does it fit into int 7,000 times that should be one point four times ten to the nine it fits I have an r8 them and then course for each query I will do them independently yep great bending point of their sort but I don't use that I can't just beat sad because that coughing has size 1 billion times 1.4 hello get into devices welcome to the stream I can't use bit sets then what should I do and also I can use a 15-3 seconds how to find that pair of buildings that are from two different sides and at the same distance from me I'm not sure that's tricky that's here I started so let's remind remember some pointer ii0 now retexe while I I is smaller than and I have smaller than X also we are given condition that X will be between some two buildings X is between 0 and and a n plus 1 so I n plus 1 this is right corner of the last building well that plus plus a high and now I I is the first building that is on the right from X assert assert a of a greater a codex our a is equal to n what would mean that X is the last that right corner of the last building if I is n then I have that last corner and I can just move I have a square and I'm off line like that here I will say cost double P is what was it two times echoes of Z zero I think let's bring that to make sure this should be value of P and here print with big precision P over 2 and continue now assert that I will put question mark maybe it's already checked somewhere the last value is P over 2 that's correct let's copy all the samples the last value is again that correct then I can even say that on the right because this is yeah because this is the left corner than out of the first building your first and last value and first of nos value like correct now I know that I'm between at least two buildings answer is is something I will check so now I also I can put assert once Mariko AI and AI smaller equal n minus 1 now for J in AI minus 1 and AI this is building to the left and to the right I'm looking for closest closer one distance is like I don't move I look minimum of a of that pointer AI minus X and X minus a of I minus 1 and minus 1 this is distance to the left corner of previous building this is distance to the right corner okay now let's use the formula you know that this turns so let's say that answer is that a sin of 1 over square root the square root of distance let's change that to long distance times distance plus 1 what do I have here that should be correct unless there are two buildings at the same distance so possibly the answer can be smaller if there are two buildings let's track first 157 178 now here I print something small that's incorrect now that if two buildings meet then the answer will be bigger the remaining two think okay now what I can do for now I will have some brute force that for every distance from zero to let's say 104 now if exists if I don't know set count of X plus D and set count of X minus D minus one then do something that will contain all the starts the left corners of buildings then answer is max of answer and two times and I think let's create let's put a function let's create a function double gate angle of distance here we go get angle here get angle of distance and there it will be two times that get angle of D now everything should be correct for samples I think shadows magic this man what a strange name for a variable I think that coat is correct but it will be slow servant even I mean I need I would have to iterate over a bigger interval then second one incorrect here okay let's let's try to draw that second sample test we have building at zero zero one two three four building here and we have we bent at zero one two three we Bend here I think they shouldn't meet or maybe they do before the ground is touched anyway are the building squares yes they are of size one times one where to learn recursion and DP I don't know from the internet Google tutorial like recursion for tutorial DP just like any other topic I say 0.78 and dancers bigger so apparently they do meet before they touch the ground that's bad I guess this point meets with with this point yes they do what about this I should add all those points to the set sir dot s insert also in that corner I have all the upper corners now without that -1 something changed let's say from the equal one and also an extra if if X is equal a of a I and this is start of that one and X is equal of a I minus one plus one then puts print the helpee the help I continue this means those two buildings touch each other at our binding point so we can't bend at all it looks fine for the sample tests the precision isn't that good now it's fine it's just that I print with smaller precision only ten digits after the comma does this much 78 92 or 78 okay we have correct solution other than this iteration that should be actually like 1 billion and then I would get time in taxes now how to do it faster I can iterate only I think it's correct to hear say magic distance times free or so maybe even smaller but that should be too slow in my opinion and let's try to avoid set and instead use pointers just not to have an extra lock to make the code very fast then I hope it will work ok I will copy dCPP tow me memo dCPP now avoid sad completely but create let's make that set and here we will create vector so it would be faster push back I push back I as well sort get rid of repetitions unique the cream of repetitions and returns and you've pointer to the end doesn't matter much now I will store an extra pointer for us and I'm looking for two values in s that are at the same distance from me just like here I did that so put here as i0 well as I small down size as of as I smell the next the process fine and now two pointers ain't I don't know is as I what is it now this is greater than or equal this is that - one for B is as I be smaller than the size and something plus cos B while I greater equals your end s of B minus X is smaller than X minus s of I - - I if I smaller than 0 break if as of V - X if that distance is equal then consider something and break what do we consider we say answer smacks of answer and two times that distance and go from distance X - I survive then this is unnecessary for now it's quadratic let's make sure that it works just like it worked previously and into not something changed I messed up two pointers I look for two things in us and as is sorted that are at the same distance from X well this is more well this is great well that this distance is too small then do not looks correct and we need some extra break if we already went too far and I will say if as of B minus X greater equal to x distance break maybe this is fast enough but submit and get somewhere maybe time limit exceeded maybe wrong answer we'll see does somebody have the maximum yeah radish and Markovski and they have had they have it for a long time already I have like what hour and 15 to the contest and they solve it hour and 20 running contests to run cancer in test two yeah it doesn't work this was a corrective yes this was incorrect let's put three times distance plus five I'm not sure what I'm doing maybe two times distance plus two should be enough if I get from cancer then I will increase that and let's think what should be there actually when we don't have to look any more distance was that distance to the closest building and this gave me some possible angle some value like this one what indeed I need a pen this is that distance D least now I know that from two buildings with the same distance from me I will have the same formula but x - 2 times our scene of the same thing 1 over square root of something some x-axis new distance square plus 1 and I wonder how big how big X I need to consider so that this would have a chance to be bigger than this I thought that it's just two times that accepted all right I don't know what is the complexity so I'm going to look at the tutorial to see if there is some proof that ranked one wrong answer was stupid because it was some sample - I should have been more careful so let's not count that okay editorial and maybe I will sit only after I finish the virtual participation [Music] okay we have i think this ten minute student is a good break for me let's change the title and do you have questions now I can look at some problem somebody has a suggestion and I think then we will likely move to the division to contest yeah this one here I still wait for to see the editorial to this contest how I can do I do occasional 65 editorial is out okay mmm drink they use bits it's blah blah blah let's conserve bit set of 7,000 positions to the left of the event and to the right of the band I thought about that but just wouldn't be faster than my social if we want to build that now maybe I understand and these will give you nth of these bits it will give you the person at that this way the cohesion they prove something how to process lots of course that just moved the bit set to the right while going through queries in ascending or okay and we can shift it and update with new buildings that appear at distance 7000 I understand understand space clones suggested some I wonder whether my social is brute force or not is it just two hundred thousand times seven thousand and what is up with this problem is it easy hard what is it about space scones say something about the problem and is there an editorial my challenge and my like China culture of challenges don't have editorials solution outlets there are some editorial stood to the contest so I can solve a problem either if it doesn't have an editorial lift and to looks at interesting or just looks like a very nice problem standing close that will I stay on the first place it took as often when I was some time to solve e or maybe he tried the dry first he was that I spent much more time on C than other guys because I draw something she was very Zant I chose but approach then the also much longer but then there was more and more explaining here also I would solve it in a few minutes but here I wanted to explain something he also took me time some time to figure out if I wanted to hit F and f was that f was very easy for me because I am good in similar problems even made blocks about that the contribution technique you can find in my blocks in got forces but G wasn't that easy week hi I get the outer size it is brought first but I don't think it's possible to construct the test against it we've given constraints we cut off my next chunk of brutes though ok thank you for information yeah I also think that should I believe you that it's brute force it's just a few times faster than what the complexity says it's very hard to construct a test where there will be so many mismatches buildings would have to be very dense close to each other but then you often get quickly a match between two buildings with the same distance but I got the solution with bit sets what difficulty would I why problems be in terms of code forces problem writing I don't know diff one D I think around defunding the hardest ioi problem is I guess different E and there are better people writing code versus rounds I mean participating in cut versus rounds but they have less time for that you can on iy you can spend three hours on the hardest problem if you solve two others quickly in code forces you have like one hour for the hardest problem what will what will I do next see ok and the next problem will be the recent gift to round five six one and if I do that quickly I will move to other problems just random problems around give to the difficulty but maybe just that will be it for now also here let's oh he wrote mainly around Davonte I totally didn't mean that I wanted to say it around DeVito D because D funded take this would take out of time sorry for that man you know that and I guess that link now there redirects to the first part of the stream yep and the second one is here links so that was part one and again the stream stopped for a moment and get up splitted sorry for that I didn't mean the 1d problems instead part 1 but I said that I will solve those runs so and they do not have problems differently and they have the first place yes I guess so 120 oh no a lot of people can still surprise me surpass whatever the word is 120 so if somebody submits in one minute among like these guys I will lose and in a moment we'll start with the last contest Division two if you have other questions to ask me now one minute break for a sandwich you once we're back solving round five six one title did I put half here I don't know and students must be splitted into two classrooms if somebody has the same first letter they should be in two different classrooms minimize the total number of bad Paris if two people with the same first letter should perfectly be in two different classrooms then I will split them evenly according to the first letter written names route names of I now let's do something cool here start everything now iterate and inside that I splitted them into even and odd indices if names of I zero so the first character and names of J 0 or equal and I'm I model toy see called a model 2 then plus plus answer I think such a split and after sorting every second person goes to different classroom and that should be correct because it splits it splits like four consecutive persons to like top person to each thing there are people that are much faster okay problems be [Music] with a worth of link case wobbly sorry for pronunciation if there are positive integers and an M such that to the vessels of case after that n times m RK and Rose and Kemp columns will speak the word to add the table and now a revolve of the English alphabet appears at least once in every row and every column every vowel has to appear in at least at least once in every row and every column so the size of row and the size of column must be at least five and given K which should print table of area K such that that happens and the right let's copy what do I want to look for for our a 5x5 I can do some pattern let's name the vowels 1 2 3 4 5 I can do the following every row is shifted a little bit now every row and every column contains every level and for K that I read I turn it over possible rows if I times B is equal to K exactly and B is at least five and then I find something like good dimensions and now I need to print something like that maybe with extra stuff to the right I think this can continue like that or let's add additional rows that will be easier here 1 2 3 4 5 and from 2 and so on now I again all the rows and columns satisfy all the conditions I will say for i from 0 to B I know that a is 5 now for every row we have string s that is a TI I will print s and then say that s is what was it as substring from first character process to 0 this should shift us by one here see out new line to Tony Rowe let's try that 725 I I think it shifts so just to make things easier to see let's put a table let's print a type of for now 25 looks shifted 40 yeah I think it's fine let's remove that assignment and I think a and B are solved what I kind of practice should I do if I want to qualify to Google Code Jam run free solve algorithmic problems and practice on Google Code Jam problems something was wrong we've test - what was wrong let's read the problem again [Music] there are five vowels and I wrote them here just in different order hey I'll eat you I a oh he UI nuts again the new line I don't know why my outfit is incorrect I shift everything by one in every role every row has all the characters and every column has all the characters they don't understand my submissions I submitted correct file maybe they can't repeat appears at least once and it's fine that they appear more than once we'll keep string size equal to 5y Alex drink of size as is equal to 5 oh no no no no no it should be a bike in Austin it's not necessarily 5 I made a mistake in it thanks for pointing that out if you wanted to point it out I'm going to sign now as pushback or a specific oh I saw as length minus 5 this went oh yeah and that that will be cyclic just this if a is greater than 5 and now we have a good-sized okay let's remove the new line even in easy problem you can make a silly mistake that happens running contest 19 accepted you can move the problem see tale of two lands something colorful to interest X&Y two markers were placed at points a absolute value of x and absolute value of y in Concord all the land in between many later the vector King placed markers at points like that okay so first somebody put stuff at values absolute value of X and absolute value of y and he colored everything in between then the other guy took absolute value of X minus y and X plus y and called everything in between and that other interval completely contains the first interval between these two what are the vows of x and y okay we are given a bunch of values 200,000 of them for how many pairs of them it's possible that those were x and y then we need to figure out what are the conditions we need to figure out what pair of x and y is and for that either we should move you should make a lot of inequalities our drawings and I prefer drugs new or maybe we'll just look at some cases [Music] okay there was this is zero this is that safe free and this is seven this is absolute value of X absolute value of y so X is free or or - free and twice seven or minus seven now what can be absolute value of X minus y there can be many because x is minus 3 or 3 y is minus 7 or 7 so the difference is one of our time and that's it yeah I think so and absolute value of x plus y is also foreign time is that so 7 minus 3 yes I think okay because plus y can take same values as minus y because we know the absolute value of y with y is 7 then minus y and plus y are both either minus 7 or 7 and in this case an interval from 4 to 10 wouldn't cover this one but that far is just value 7 minus 3 and this is 7 plus 3 so I think for positive values that are given x and y the weight amount we know exactly what is x and y ok nevermind four-month so this doesn't count but what counts is I guess we want that difference to be smaller than X we want let's say that we have X smaller equal Y then the big interval should be from Y minus X Y minus X smaller equal X smaller equal Y smaller equal X plus one assuming that those are all positive values I think and this would for example be true I think for values 5 & 8 it's just that Y should be at most two times bigger than X and then this condition is equivalent to Y is more equal to X okay plus we have here some signs of x and y but I don't think they matter because here anyway we take models of them like absolute values of them here we can change sign of minus y and plus y and this will just swap the two things so I suspect that signs do not matter and it's about counting pairs X Y such that one is at least two times bigger would that work here 2 3 & 5 and the only such pair is 2 & 5 here 3 & 6 this is one part now what about the 0 0 & 5 would give us 5 & 5 this is incorrect but 0 & 0 would be fine but numbers are distinct so two zeros are impossible okay I think we I'm done gather all the numbers ignore the sign science compute the number of pairs such that the bigger number is twice bigger I repeat and times index root X if X is not 0 this is how we can write a pushback absolute value of x solve and now I hope I will use two pointers I could also use binary search I let's use lower bound serve is zero for everything for every X in I answer plus equal maybe that's first some twist let's say that this is I this is lower bound from I begin I end two times X this will find this function lower bound finds the first element that is at least this value and I will say that answer is plus equal a and minus that the difference of these two pointers will be the number of elements that are at least that I got one instead of a wait a moment I got a - and here I have one / so I think is wrong or do I can't Paris where I counted something incorrect I need to count stuff that is at most twice bigger the bigger numbers is the most twice bigger so let's let's still just to practice use the lower bounds so the upper bound will give us first bad value one that is too big - is there something like find lower about I begin I end two stacks this is my position and this is that first bad position and minus one because if my position is is five and first bad position is 6 then I don't have any pairs - well during a contest I think I will I would use two pointers but now I wanted to try something different instead of just using two pointers all the time today during the strip by the way when when you solve problems and something is hard for you then you can just see what topic it is and today I see that a lot of times I see something for two pointers something goes wrong maybe my there are two possibilities either at least either my algorithm is incorrect maybe this is not about looking for pairs that that condition is true or my implementation stroke maybe signs do not no matter maybe something is wrong here what is wrong what is wrong maybe some overflow I have a salt I got wrong answer am I sure that zeros do not form any correct parts 0 & 5 will give me 5 & 5 this will not cover yet this is a bad part these things so I can take two zeros what if X is equal to five and what if X is equal to by five five then here I have zero to hear ten correct Oh two equal values okay see mmm - five five I got five it shouldn't be five let's put a pair bound here and I should have iterated over index let's do that I I from zero to a size do that actually upper bound is not that necessary I could just use I in some way plus one or so if I is at least one and a of is equal a fi minus 1 plus persons and exes i fi minus five five one four two equal numbers i computed them as two pairs and it should be just one I don't do well in this contest already two wrong submissions and each one means four minutes wasted next problem will be will be deep cute sequences ecologic copy templates and I think I can change title as well good sequences actually that dark word says solve e first but I want to during the contest I would now jump to e but I want to go in the order to make it to make it easier to find it later during this watching of a stream after the strip sequence blah blah of positive interest is M cute if forever index it holds that X I is the sum of everything previous plus some her eye and her eye is in this interval you'll be given Q queries consisting of bhava for each query you must determine whether or not there exists an M cute sequence whose first element is a and whose last element is B find an example of it from different course let's think I can just say that a f1 is a our f1 this RFI says that the number is element is equal to the sum of everything that was previously plus this RFI so I will say that then I have two is f1 so also our f1 plus f2 we are free is everything previous two times are F 1 plus RF 2 plus R 3 this is the sum of this 1 this 1 plus R free EF 4 is 4 times this plus 2 x dot plus R 3 plus R 4 F 5 is 8 is the sum of all previous are ones plus that Plus that and I think we can see the pattern we will put 1 here 1 here should we tell you if we spot stupid bugs like the previous one that's a good question maybe not if I'm stuck for half an hour it's a good idea but if it's something that I just think about four or five minutes it's better if you see what I do when I have a lung cancer you can learn how you can do back or think about mistakes so it's better not to tell me during first few minutes okay for every number AI is the sum over powers of two times all ours and then we have some assuming that for example n is equal to 5 then we are given that a of 5 and we want to know we are also given our 1 this is some value the question is can we chose our 2 3 4 & 5 2 so that each of them is in interval from 1 to M M is given in the input and the sum is satisfied they called the length of a sequence K instead of n we are not given the length in particular if a sequel to be then we can just print sequence of size one and what do we do for those Paras often I think we I will move greedily from big numbers to small ones and I will put as big as big numbers as I can the issue is that I can run out of numbers the limit and the upper limit limits my my number here we reach Q queries actually I will call those test cases because they are independent and we must be careful about long axons not overflowing and what do we have I is the first a B and I will cut those I will call those numbers from the input uppercase I mean I will name them this way to distinguish from my arise and maybe I can enter it over length if a is B first of all then just put the dot say length and then that one and it then just a Twitter otherwise we need bigger like 4 and from 2 up to 50 they allow me the length up to 50 I don't like the fact that here they say about length and here about length okay that's strange first of all the last number will be some pair of two times that first number so this is a we write down is our F or F 1 B is AF 5 of n this is a and now there is some formula long long already is that I shifted by n minus 2 for n equal to 2 here it's shifted by 0 here by 1 and so on okay so this is this way I compute the value here if already greater than B break this is too big and at the end put impossible otherwise we want this Sam for clunk remaining maybe we don't always we shouldn't always just take maximum give me a second because our I must be positive it must be at least one I will say even more for already plus equal there must be at least one here one here one here one here our I must be at least one so this will sum up to 1 plus 1 plus 2 plus 4 which is here 8 so I will say that this is a plus 1 shifted instead of saying just that already the Sun already is 8 times r1 I say that I get a 5 is 8 times r1 plus that 4 plus 2 plus 1 plus 1 which is 8 and then I put it as r1 plus 1 and now I say that every RI can be 0 if it wants and then our I in 0 2 and minus 1 for each eye from 2 to n okay remaining is B minus already and now for each power for example from 5 we start from 2 - - in AI equal to 2i up to home plus plus I long long now that power of 2 power of 2 is 1 l 2 and minus 2 L minus I that would give here 8 it's n minus 1 minus 1 maxed with 0 I think that's the exponent we can check on example often the mistakes plus minus 1 you can just check on an example to see if maybe this should be plus 1 or 0 for n equal to 5 and I equal to tow this will give me 5 mr. Nelson - and indeed this is 2 to the 2nd power then this is one smaller one smaller and this is max - 0 I think it's correct then x is minimum of remaining over Peto how many times we can take this power with what multiplier not to exceed the value remaining that we still need and minimized with a minus 1 that's the limit and we say what do we say remaining - tikal times time x times P - if remaining is 0 then puts I can't return but actually we should find the sequence what is wrong expects 10% music copy the sample okay and now we need those values you can create a sequence long long this will be the answer the first number must be a and then your value is zero for everything already in answer say new value classical answer this could be done faster with maybe I will maintain them prep some is I and then new value is prep some plus RI and our ice times mmm or plus one Oh some next I think yeah plus one because x is from 0 to n minus 1 actual values are between 1 and M and also push back new value grab some classical noodle if remaining is 0 then print and and for everything answer prove it print it you can also notice coughing if you want to print size of something and then with spaces those numbers then don't put space here after n just put space before every number then you avoid an extra space at the end what is usually not important but it is only butter I have a mistake like buy one here it looks quite strange or maybe this is not a mistake Emma was a tool and I can say that this is previous number plus 2 then this is the sum of previous numbers plus 1 and this is the sum of five seven twenty twenty twelve plus thirteen twenty five okay it's correct let's submit I tried to also think about possible overflows here but I think everything is fine also because of that check when numbers start becoming huge I will break already in my opinion I think I hope so except now it should be an easier problem copy to be cpp change the title The Sims must be like Dora the Explorer Bubba and stars numbered from 1 to N and the I've store has offers a positive integer a I M days every day she bought a single integer from some of the stores so single integer some integers from some stores swap I offered the frogs bought a single integer from all the stars that Dora did not buy an integer from on that day Swiper is her rival least common multiply of the numbers she bought Hyundai is strictly greater than that so if your statement is so artificial like LCM of something I don't think that having a story at all is a good idea hard to say if it makes the statement longer than it's about ad and this is not very real life problem if we talk about we take we care about LCM of two sets of numbers forgot the values I if there are positive integer values of AI such that she beat Swiper on every day you don't need to find the water possible values of AI though some voice AI can be same also if you put a set a subset of numbers from 1 to n as the input just then put it us 0 0 1 and so on this is easier to understand to see what happens or maybe not it isn't a very big deal for each of em days we have some subset of indices and we want to say that that subset should have LCM greater than the complement of that if n is equal to 5 I think in the first sample if one of dice is 1 2 3 it means LCM of numbers a 1 a 2 a 3 is greater or greater equal strictly greater than LCM of a 4 a 5 how to even approach that and we must say yes or no possible or impossible that all the conditions were satisfied the first sample squat is because in both sets we have shop free and possibly in shop free there can be a huge number number with value 1 million and then we will assume of those numbers will be bigger if if one day we have a set like one and two and the other set like three and four we lose because this should have LCM greater than all the everything else even for an equal to 5 this should have LCM greater equal done everything else that's impossible that's contradiction every two sets from the input should have some common element maybe this won't be common for everything so these are three possible sets and now can I make can I win for this for those sets can I choose proper values let's put here free free four or even hard dot this is not hard what about this freefall four five and five one and n is equal to five each of those sets has size - so it's there is some disadvantage compared to the other three elements oh but these two are disjoint so the answer will be no maybe the answer is yes if every two sets have a common element and have no idea how I would prove that one two then one three two for free I don't know let's implement that approach and see if it works it should be fast max and is that which set of Max and B of 51mm great payment L for everything for every day with K 3 K times with X and say B of that day of Jace one for every two different days if we'd set of a and bit set of J is equal zero puts impossible to zero otherwise every two dice have a common element let's try four samples impossible first of all this is so here I say possible here impossible lower case possible and possible oh no it should be impossible those sides have different stuff something is wrong here I should hit impossible what happens what happens he runnin into a possible why do I make loops correctly I think I have a silly mistake or I don't read the input correctly I track all the paths for almost any two of them they don't have a common element so their end should be zero let's decrease that to like I don't know 15 and let's print that if that's possible everything has the last bit set to 1 so the bit 0oj I should use X impossible and possible let's try sometimes if you have no idea how to solve a problem then assume that social is easy might work the approach might work and also let's remember that there were there were a lot of accepted submissions oh no that's bad wrong cancer Maxon that's stupid back what I usually do and I should have done here is when I change something for a moment then I put a warning here warning increase max and yeah except and then if I compile it compiled successfully but it has a warning I remember to change also I could use flag local and to something like if death locale local then put that what was it a leaf put that and I think else and I think that should work locally with 15 and when I submit it should be 10,000 I should have either done that or I should have put a warning and remember about it make be careful not to submit anything we Forex then then I would avoid your examination last problem F title code I think this will be the last problem for today the stream lasts for four hours and I will just finish after this problem and cities samples are connected magic is unstable so at any time neurons may appear between two cities Wakita which has been tasked with performing deliveries between some parts of cities how do we manage your mental energy so many problems in one session four hours isn't really that much is it early does month-long ICP contests lasts 5 hours and they are they have hardware problems marathon contests last 24 hours [Music] she can only complete a delivery if she can move from starting city to her destination city for a double rainbow cities the route connecting seat to I with that and that have the same color like there are two routes to red route then to blow routes to whatever okay [Music] there's a list of events in chronological order where each event is either a delivery she must perform or appearance of a new route if time limit is four seconds which is quite high and limits are up to 100,000 then often we should do something win complexity and square root of n' let's remember that number of routes cities routes initially present different colors the number of events can you please solve this problem using crackers I won't do it today if this is just Fibonacci I think this was the first problem you had cutter contest them you can search in the internet for that or asking asking discard competitive programming this code link in the description cue lines follow meaning around with colors as appears between that you should determine whether we can make a delivery delivery starting at city X and ending at City y I think that this will be will be similar to problem with clicks when we have when we are in some city the problem says after we travel the first route that it have black color then the second route also must be black then if the next color is red or whatever this is the next one also must be red so I will say that if there are red some red roads coming from one city city doesn't have a color it just that now I draw in the red then you can jump between each of those those cities those that are connected with the middle one from example you can jump from this one to this one and this is a lot then again you must take two blue rods then two green roads may be repeating or at least you can put point out my mistake not now I'm just asking this card because I guess this is something easy okay and now when new route appears there was a city that was already had several roads and this is not that is also black deeds allows us to travel between this a and any of those b1 b2 b3 before we can jump between a and any of those be high let's I will take a look at dashboard to see how hard these problems quite hurt that's also some hint somebody solved F but it's for sure a fake account with 12 minutes forever nobody it solved everything actually nobody soft in the tubs alt F okay we can jump between a and anything there I can create I can say that this city in the middle let's call it m has a copy M Prime and actually you can travel between each of those b1 b2 b3 before with M Prime and also that before and then from M prime you can travel to a and I'm done removing those edges because you cannot travel between m and something you can just I'm jumping by two every time and now this graph allows me to go between a and and EB I actually between bi themselves as well okay now if the path that we need to make is of even size the number of addresses even then we are done it's about adding edges applying some faintin Union and saying that we asked if two vertices are in the same connected component but maybe we will do several jumps like that to black edges then two red edges but then one last edge can be the standard one so I think we need to figure out the following given those two vertices from the input meaning corrode yeah can make the restarting attacks starting at X and finishing at Y I want to know if there is such a neighbor of Y that I will call y prime that I can jump between x and y prime with those those jobs well this term is education the white not in main channel problem-solving will be in secondary tone I can discuss that later or ask me during boring streams while Prime okay thus why have such a neighbor that it's in the same connected component as X then either if Y has small degree then I can just iterate over neighbors of Y the issue is what if y has big degree what if y has huge degree but then that's often the case with graphs and n square root of n complexity that you split vertices into two types those with degree bigger than square root of N and those with degrees smaller than square root of N and there are only a few vertices greater than big deep gray in the graph the number of vertices V such that dag of V is big is greater equal square root of n is smaller equal than square root of n itself where n is actually the number of edges there can't be many vertices that have huge degree because then the graph would have quadratically many edges and maybe when I do Union when I connect something I can iterate over big vertices big vertex means vertex that has big degree big vertex when I do Union I can iterate over big vertices and do what check if something changes for them or I could for each big vertex remember the which connected components are among its neighbors but I don't know how to update that I could also use some bit set to star neighbors of something mmm I think this problem is quite hurt there are only a few vertices that can have big degree for each query I can just iterate over them linearly and then do what if that Y Prime has small degree then when I do any union I can iterate over neighbors of such wipe rambling that changes and notify all its big neighbors big meaning big degree like Hawaii that high from now on one of your neighbors is in this connected component in connected component of number five for example but then the issue is what if both y and y prime are big vertices but then I can for acquire iterate over all big vertices and check if y and y prime are connected okay that's done and I need to now implement it you know the some solution summary let's see how much time I'm left 50 minutes that's enough the social summer split vertices into beacon spawn big means it the degree greater than square root of m2 account degree I'll first go over through all the queries and count degrees final degrees to split into big and small then when something changes with Union for everything that is being changed like this vertex and it's not big itself I go through its neighbors and I notified them that I you have one of your neighbors in in connected component of number then also for to deal with those jumps of size two I for every vertex I create one fake vertex M Prime and I connect them just like I shout on the left and then when we have a query from X to Y and twice big I also author iterate over all other big vertices y prime and I check if x and y prime is in the same connected component and Y and y prime I collected is this calculate the composition no it's not a VI decomposition is something that is done on trees this is not a tree this is just one of many I don't know problems solutions with square root complexity and the number of cities address colors if you don't think this matters count colors and queries with everything also I said that there is fake there is fake vertex M prime actually it is for every color that touches M that's a little bit harder I didn't want to do that I'm like those are initial lines a B C and B are connected with color C I'll fetch a VC I will call now I will write in a way that is comfortable for him for me I usually named the Max and Max and what do we have we have degree of Lux we have edges that go from each vertex we have function hard-edged that will do the following we have edges of two types actually the single edges and those double edges double is impossible to not double just what rainbow this is how spot yeah single of I push back single of be pushed back and now two times repeat the following and then swap a and B I said that I create a copy of M when I create new edge between m and I so here I will create copy of B you get ID from some vertex and some color I was told a map from pair to called to int this is to ID now if two ID count make power I see the Naruto ID of dot / AC else next ID is next available ID and I already have values from 1 to N so next I do n plus 1 copy of B will be copy is the big veto is get idea of B and C this is that version that copy of M and prime of b b prime that corresponds to this color and with that function as return the ID of tracy sequel next ID + + that function for each per city and color unassigned another index Beto is get ID love that and then put at brain wall of B to push back a rainbow of a push back B to I'm adding H that this one between a and M prime just M prime is called B - in my code okay that adds edge what else the degrees those between a y and y prime are important important only for single edges most standard ones now I will read the queries to remember them to remember the great to split into big and small vertices where is the statement queries [Music] vector inquiries of q4 vector int and choir II a inquiries type read the character we've typed is zero not not 0 if type is plus then read ABC increase the grease query or is equal sector ABC else maybe maybe and Claire is a gospel degree of I plus plus degree of Li okay now according to degrees I need to what is wrong according to the grace I need to find big vertices not declared I can make this the same way I wrote it a line below the Paris okay then what do I do I find big stuff I can put some constant here that I will change later and I will experiment a little bit with its value to know what it should be here for now let's say that that magic is 5 in is 2 but here warning change to something around 300 1000 this will be the condition for at least the smallest degree such that we say the vertex is big I don't like the fact that the sample is so short it should be some big raft tracks more stuff for everything up to em wait a moment these are rainbow edges and these are sink okay only single so only from one to end is important for me even the gray of ice at least magic then this is one of big vertices big pullback high maybe also is big of nax and marketed now we need to go for course if we're it size is free this is mu H is query of zero B square e of one C square e of to add H of ABC just like we do here and on graph of rainbows actually I don't even need to push back anything I'm need find an Union okay so let's write my final in I have G which is group of someone and if that is vertices in F of I or maybe let's call that CC no in the Stars vertices in connected component number I and this is the connected component or group of vertex I we we initialize that every vertex is in its own group and here I don't think I need to rainbow it all they don't want to start those address I need some fountain Union so this will be unis of and Vito be the is G of a bistro be if is be continued if I size is greater than besides this is smaller to greater principal for everything in in the fall I Jeff X is B in for big positive x clear at the end I'm putting smaller connected component to bigger all also by the way my complexity will be log from that times square root so I will have n square root n times log or maybe n square root of n times log I want to have this complexity of an times square root of n times log of it first I will need to just proper constant here okay unique and as I go culture I need to I think iterate over big add big vertices and do something with them they will need to add some field but then add edge and that's it else we have a choir from X that is query of 0 to Y that is query of 1 if Jeff X is equal G of F Y or just let's say puts query off I'll search query X Y and this here I say yes or no and let's have a function if G of X equal G of Y return true then I want to know is there a neighbor Y prime of Y such that G of X is equal G of Y prime I can just iterate over such thing over single of Y with G of bees equal G of X well control but for now this is quadratic still I can check it for the sample tests approaches X yes yes no I will copy this to memo F CPP by the way after the stream I will put everything in my github repository if you want to use an account feel free to do it or just read it and now instead of that I will do if not is big off why then do that otherwise assert is big of why and I need to track for int B in big other big stuff if G of B is equal G of X if this is another big vertex and there are connected B and Y are connected I mean there is an edge between them at all true but I need to implement that the last thing is that then that neighbor of y y prime is not big and I will start so complicated first are connected what is fast way to implement that I can have a set but this would be quite slow I will say also week big of Knox every big vertex will have its index which big of a is big size from zero to some number then we size increases by one and then I have edge for connected well big connect that be connect of now what let's put for now four thousand times four thousand it I think it should be greater equal something that knocks over CC but for now I can't put trust so big values because not and this is magic and here those are connected connect that of a and B assert big is big of a and is big of b return big connected of which big of a and which week of B with a single-edged and when we add edge Prasad edge here if this big of a and is big of B then is which big of a B is which big of being big connected of a b c public connect that of ba [Music] okay the last case is NaN why is big non small neighbor with in the same connected component with X but let's incorrectly return false here to see if it looks okay none samples it here works on samples but what shows that samples are very weak now I need to implement this and can I do it I think I don't have time because I need to do something before 5:00 p.m. so I will not finish that today I need to go leave my apartment now I wanted to finish of course I'm I don't believe that everything else here is correct I'm sure I made some mistakes that's one thing the next thing is that I think I will have to fight with time limit that I will have to squeeze my solution so it's quite dangerous when I I think I will finish that during the Sun stream or if not then I will anyway record my fight with the problem yep problems codes will be later put in the repository that's it guys for today thank your for watching so this was like four and a half hours I hope you liked it you can suggest to me in this quarter Facebook which streams I should do more often which less often so I would be able to decide better next week I think again I will make three streams so alright and yeah subscribe to this channel and Electr just without - and check out those two videos on the main channel youtube becomes larger Plus what yeah subscribe like share with your friends tell your friends about the channel and thank your for watching and commenting I need some comments in twitch like update okay mmm bye bye everybody see you Monday
Info
Channel: Errichto Hard Algorithms
Views: 68,306
Rating: undefined out of 5
Keywords: programming, coding, algorithms, algo, codeforces, C++, stream, errichto, hackerrank, bps, boring programming stream, problem solving, icpc, topcoder, codechef
Id: b1_sHTh0Z1k
Channel Id: undefined
Length: 211min 29sec (12689 seconds)
Published: Fri May 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.