Блог пользователя Ezio07

Автор Ezio07, история, 8 лет назад, По-английски
Tutorial is loading...

Problem Authors: GT_18, karansiwach360

Author`s Code: 42406878

Code Complexity: O(LogN)

Tutorial is loading...

Problem Authors: csgocsgo, karansiwach360

Author`s Code: 42406891

Code Complexity: O(NLogN)

Tutorial is loading...

Problem Authors: csgocsgo, Ezio07

Author`s Code: 42406848

Code Complexity: O(N)

Tutorial is loading...

Problem Author: Ezio07

Author`s Code: 42406857

Code Complexity: O(NLogN)

Tutorial is loading...

Problem Authors: dhirajfx3, GT_18, TooDumbToWin

Author`s Code: 42406908

Code Complexity: O(NLogN)

Tutorial is loading...

Problem Authors: karansiwach360, hitman623

Author`s Code: 42406921

Code Complexity: O(N)

Tutorial is loading...

Problem Authors: 300iq

Author`s Code: 42406934

Code Complexity: O(262 * N + 26 * Q)

Tutorial is loading...

Problem Authors: dhirajfx3, DeshiBasara

Author`s Code: 42406942

Code Complexity: O(|x| * LogN * 26) per request.

We hope you enjoyed the problems!

Hope to see you all in next edition of Manthan.

  • Проголосовать: нравится
  • +70
  • Проголосовать: не нравится

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone tell me why i am getting this error in my code it is working fine in my compiler 42407188

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +14 Проголосовать: не нравится

Ezio07 It would be very helpful if you could add Time Complexity for all the proposed solutions. Thanks!

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

another solution to problem A:

As was written, the answer it's number x for series of numbers: 1, 2, 4, 8,..2^x. This series of numbers it's geometric progression. The sum of the geometric progression is given by the formula: S(x) = (b(x)*q-b(1))/(q-1). For 1, 2, 4,..2^x q=2, b(1) = 1 and b(x) = 2^(x-1) => S(x) = (2^(x-1)*2-1)/(2-1) => S(x) = 2^x-1. The following condition must be met for the answer to be correct: S(x)<=n => 2^x-1<=n => n+1-2^x>=0. The code this solution: 42408562. (sorry for my not so good english)

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

can anybody tell me why iam getting wa in test case 11 in D problem https://ideone.com/r2c4K5

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -14 Проголосовать: не нравится

Can someone tell me D's solution? I read the D's tutorial and read other source codes, but I can't understand. What does D's tutorial say and what is the solution?

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    For understanding what the tutorial is trying to say, first you need to understand how graph is stored in an adjacency list and BFS Order Traversal. If you understand these two things, then you can read ahead.

    Basically, the way you store nodes in adjacency list, determine how your BFS Order Traversal is going to look like.

    So, for checking the given BFS Order, you store the neighbours of a node in the list according to the order they appear in the given BFS Order Traversal. Basically, "we can sort the adjacency lists of all the nodes in the order in which they are present in the input BFS Sequence." (as mentioned in editorial)

    Once you get the adjacency list according to given BFS Order, Do BFS on the list and then check whether it matches the given order or not.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    Here is my editorial to D. Let me know if it helps :)

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can somebody tell me what is wrong with my code (42403836) for 4th problem.Actually I am getting WA on test case no.11 which is a large test case that is why I am not able to debug it.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -19 Проголосовать: не нравится

Can we do Problem D using Dijkstra's algorithm with edge weights set to 1 ?

Input order should be in increasing order of distances from the source.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    If you ever use Dijkstra with all edge weights as 1, use BFS instead. But I don't think it would work. You have to add all nodes connected to the last node in some order, but you can't mix them with other nodes (even if they are on same distance from 1).

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My submission for B is in queue for too long. 42412545 What should i do ?

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone tell me why i am getting this error in my code it is working fine in my compiler 42399951

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can Someone Explain Problem B? Why are other elements modified when only the median needs to be modified?

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Median is middle element in a sorted array.

    Now, modifying Median may break the sorted order of the array elements. So we make sure elements before the median are still smaller than new median and all the elements after median are larger than new median too.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Still wondering: optimality proof for A, anyone?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

Can anyone explain G more clearly?

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +25 Проголосовать: не нравится

    For each character c, you need to precalculate grundy numbers of strings between consecutive occurrences of c, their prefixes and suffixes. When a string s breaks into multiple strings, the first part is a calculated suffix, last part is a calculated prefix. For other parts, you can keep prefix xor of the calculated xors. So suppose you have a string adbecbdabfr and query on dbecbdabf and you choose character b (as your first move), the precalculated grundy numbers will be of ad, ec, da and fr and their prefixes and suffixes. To answer the query, you take d suffix from ad and f prefix from fr. ec and da can be retrieved from prefix xor.

    There are n + 26 such strings. You can consider them as queries while precalculating and order them properly such that the required values are calculated before the query.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Why actually "The best possible way to distribute the coins is to create packets with coins 1,2,4,…2k with maximum possible k such that 2⋅2k−1≤n. " is there any proof about that ? I have solved the problem and I still don't know why this happens!

  • »
    »
    8 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    To be able to make 1 you defnitely need the coin of value 1 so it has to be included.d now to make 2 you can include another coin of value one to sum to 2 or you can use a coin with value 2 so that you can make 3 as well so using coin with value 2 is optimal. You can go on inductively to show 2k is optimal.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +7 Проголосовать: не нравится

    Lets assume that we can take <= log2(n) coins. We can choose some of them in 2^log2(n) = n different ways. So there are at most n different sums. One of them is 0. So we have at most n-1 non-zero sums. It is not enough to cover n numbers(1, ..., n). Thus answer is not <= log2(n), answer is >= log2(n)+1. So, log2(n)+1is optimal answer.

    Now we have to find log2(n)+1 coins. These are 1, 2, 4, ..., 2^(log2(n)+1). We can prove its optimality by induction. First i coins cover numbers [1 ... 2^i-1]. Next coin is 2^i. With that coin we can obtain also sums 2^i, 2^i+1, ..., (2^i+2^i-1 = 2^(i+1)-1). So with first i+1 numbers we can cover 2^(i+1)-1 coins.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I see that many people make arrays/vectors of size 2e5 + 5 if max number of elements is 2e5. Why is it not 2e5?

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

can anyone tell to me in task A why we can not do this with smaller number of packets?

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +28 Проголосовать: не нравится

Let me clarify problem E a bit, for current explanation goes more into details and less into the idea.

First, we build final graph of friendships. Then we delete from it all nodes with less than k friends — those buddies weren't going anywhere anyway.

The interesting observation is that all the remaining people can go to the trip on the last day. Now we can just play the time backwards. After we removed edge which appeared on day n and also all the nodes with friends number below k, all remaining nodes can go to the trip on (n-1)-th day. Then do the same thing for n-1, n-2, et cetera. Need to print results in reverse order though :)

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by Ezio07 (previous revision, new revision, compare).

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

solved F with Divide & Conquer 42425616. Actually it's quite similar to the one in the editorial.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why the code of E is so long......

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Just have a look at the solve() function rest is just template.

    Solution
»
8 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Nice solution for E...

Will definitely give it a try

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Problem F

Can someone push me in the right direction? I can't figure out how to get l and r for each element in linear time.

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +33 Проголосовать: не нравится

For problem F, Can anyone give an explain about how to calculate number of segment in [l, r]? Also, why the segment is not k, 2 * k — 1, 3 * k — 1 ... ?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Could you explain, how did you solve the query part in O(|x|* LogN *26) per request? I solved it in O(|x| * LogN * LogN * 26) . I first build the suffix tree of given string. Then to find whether there is an element in range [l,r] in given subtree, I use binary search on each node of segment tree which are visited during query. Hence, there would be O(logN * logN) for each character (from 0 to 26) for each index of x in the worst case.

  • »
    »
    8 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +19 Проголосовать: не нравится

    Consider of example the ith position of the array of leaves has value li, now we will be maintaining a set of persistent segment trees from left to right, that is persistent segment tree for ith leaf is obtained by adding value 1 to the li position of persistent segment tree of leaf i - 1. To do this, maintain three arrays, seg_tree, L_ptr, R_ptr. The node represented by integer id c will represent-

    1. seg_tree[c]: The sum of values in the segment represented by current node.

    2. L_ptr[c]: The left child of node represented by c.

    3. R_ptr[c]: The right child of node represented by c.

    Now to add the value li to the persistent segment tree of leaf i - 1 and get the root node for the persistent segment tree for leaf i, we can adopt the following algorithm.

    If we have persistent segment of node i - 1 as c, we can obtain persistent segment tree for node i by calling add(c,0,|S|,li).

    Code snippet

    Now to find whether the current subtree contain any value in the range L ≤ R,

    Let a + 1 be index of left-most leaf in the current subtree, and b be the right-most leaf in the current subtree and pj represent the persistent segment tree of leaf j.

    Now we need to only take two segment trees pa and pb and query if sum of values in the segment L... R is non zero.

    To do this we can apply the following method or say call find_sum(pa, pb, 0, |S|, L, R)

    Method

    If returned value of the above function is non-zero then there is some value in the range L ... R. You may also like to see the find_first method in the code given in the tutorial to find the smallest value which is greater than L but less than R.

    So this is how we can check in O(log|S|) time whether there is some leaf in the current subtree with value in range L ... R.

    Let us know if something is still not clear.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Может кто-то придумал решение на H с асимптотикой O(n * sqrt(n * log(n))) или лучше? За счет трика что уникальных длин около 400-500

»
8 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D. Test Case 39. Given Test Case - 2 1 2 2 1

My opinion — Yes. But the checker says No. Can someone Explain to me why the answer is No?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can you guys write the last part of the Problem F properly, more clearly?

»
8 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Just do cout<<(long long)log2(n)+1 in Problem A

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

About problem G. Editorial says we treat precalclulating like queries. So we iterate over character c and use two prefix/suffix dps and one range query. But yet we dont know grundy for each gap between two equal characters, we cant precalculate prefix xors. We can use segment tree, but than complexity becomes n*A*A*log(n) which is too long. So how to accomplish precalculation?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Here is an O(n) solution to D :

42464470

»
8 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

In problem D we need to check if the BFS sequence is valid or not. The editorial solution is really easy to understand. I guess same approach can be used if the problem was to check for valid DFS sequence.Only change would be that a DFS will be used instead of BFS. Can anyone confirm this, I am not 100% sure about it!

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anybody help me understand 1037E(Trips) problem??

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain the E question clearly? I dont get the author's logic

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For D, I made an array par, for which, par[i]=j means that j is the parent of the node numbered i. I constructed a queue, Q that is used to imitate the BFS. Now, I add the current node (first node initially) to the queue, and check whether the next k nodes (where k is the size of the adjancency list for the current node) have the current node as their parent, while adding these nodes to the queue Q. After these k nodes are checked, I remove the current node from the queue.

This will work for any order of neighbor selection for the BFS. The submission can be found here. It doesn't work for the test case 12. Any ideas? I think the implementation is correct, but there is some problem with the concept.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

We can perform Problem D in $$$O(n)$$$ using two-pointers.

80832291