this is the most beautiful question that i have solved….
this question is more of a datastructure problem.. we have to use Union Find datastructure and a custom data structure(maplist) which allows to sort specific points of an array(sort values which are in specified indices)
there are still some optimizations to do…
simple math derivation. all you have know is that
sum of the roots = -a
product of the roots taken two at a time = b
i don’t see how these two are different versions of cpp are different but i’m getting SIGSEGV for arrays and getting AC when vector is used…
and the python version of it is here. actually there are no submissions in python…
another mathematical sequence, the sequence should be precomputed. during the precomputation it is better to use a boolean array instead of a dict. to know about the size of boolean array first you have to make a solution using map and find the maximum value in the sequence in the range.(which will be your size of boolean array)
since it is mentioned that there is no intersection, you can easily visualise a subproblem.. since there is a connection between everyone, try to make a connection between 1 and every possible other(2, 4, …) and just solve the sub-problems..
a simple memoized recursive solution works…
simple one, but as always giving tle for python solution of same algo as cpp solution(this one got accepted)
another simple problem, but O(n) algo in pyhon is giving tle, dict doesn’t worked either..