Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

# | User | Rating |
---|---|---|

1 | tourist | 3602 |

2 | LHiC | 3287 |

3 | Radewoosh | 3266 |

4 | W4yneb0t | 3181 |

5 | TakanashiRikka | 3178 |

6 | moejy0viiiiiv | 3122 |

7 | izrak | 3109 |

8 | anta | 3105 |

8 | Um_nik | 3105 |

8 | ershov.stanislav | 3105 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 178 |

2 | csacademy | 167 |

3 | tourist | 165 |

4 | Petr | 164 |

4 | Errichto | 164 |

6 | Swistakk | 158 |

7 | matthew99 | 152 |

8 | Zlobober | 151 |

9 | zscoder | 143 |

10 | GlebsHP | 137 |

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial is loading...

Tutorial of Codeforces Round #381 (Div. 1)

Tutorial of Codeforces Round #381 (Div. 2)

↑

↓

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Aug/21/2017 03:51:19 (c2).

Desktop version, switch to mobile version.

User lists

Name |
---|

Could someone please look at my code for 739B? I was getting WA on pretest 15 and am not sure why...

I store the 2^k ancestors and the distance to them in bparent[][] and bdist[][]. I then binary search for each node that controls the node that I am on and store the start and end segments in event[]. The function solve() dfs's through the tree, keeping track of how many nodes each node controls.

Thanks!

For problem D, how do we store the ancestors of all nodes in O(n)?

You only store the (2^k)th ancestors of a node -> O(n*log n)

Can someone explain the approach for the problem 'Alyona and Tree'

This is the binary search method that may not be the easiest, I recommend checking out zawini54's comment too!

A few observations could be made:

dist(v,u) =dist(root,u) -dist(root,v)v, and its ancestorsa_{1},a_{2}, ...,a_{i},a_{1}being thefurtherestancestor (root of the tree) anda_{i}theclosest(immediate parent vertex),we can see that

dist(root,a_{1}) <dist(root,a_{2}) < ... <dist(root,a_{i}) <dist(root,v), a sorted sequence that is binary searchable.v, we want to find the number of verticesuit controls, i.e.:dist(v,u) ≤value(u)dist(root,u) -dist(root,v) ≤value(u)dist(root,u) -value(u) ≤dist(root,v)for each vertexu, which verticesvcould controlu?Ok, for each vertex u, I can find how many ancestor controls it, but how do I use this information to find out the reverse?

this can be maintained using segment tree on the path from root to current vertex

Let u is controlled by x vertices. Then the immediate x parents of u could control this vertex u.

But a simple approach in getting the answer requires O(n^2) which would fail on the time limit. Can you suggest a better approach?

Consider the array,

A= [6, 1, 6, 9, 3]We can compute an array of differences between the neighbouring two elements, a difference array,

D= [6, - 5, 5, 3, - 6],Note how we can reconstruct the array A from its difference array D,

A[0] =D[0]A[1] =D[0] +D[1]A[2] =D[0] +D[1] +D[2]A[3] =D[0] +D[1] +D[2] +D[3]A[4] =D[0] +D[1] +D[2] +D[3] +D[4]If we can somehow first construct a difference "array"

Dfor this problem, then we can reconstruct the answer "array"Afrom it.Nice thought.Thanks a lot.

Sorry, I still do not get it. How do you get this difference array?

Actually there's another solution that doesn't use binary lifting, but the merging sets technique. I think it's easier, because at first I thought of doing something with binary lifting but wasn't able to come up with anything. Check it out: 22490570

Nice approach, btw are you making reference to the technique disscused at this post?

I considered merging set approach during contest, but couldn't find a way to count the number of elements <= d in O(logn) using std::set, now I know it's unnecesary for this problem after reading you code.

However, if the condition change to that v controls u if dist(v, u) <= a(v) (instead of a(u)), it seems we must have a way to count the number of elements <= d in O(logn) using merging set approach, and std::set doesn't satisfy this.

Actually, I don't think my approach works with the harder version of the problem, since it relies on that fact that d(v) is monotonically increasing as you go down the tree. I think there should be a solution involving segment tree and coordinate compression, but I haven't thought about it that much. Please feel free to correct me on anything.

But Ordered Statistics Tree does. Can't we use it instead of sets?

An explanation please?

my solution using ordered statistics

Can someone please elaborate the binary lifting method for problem D?

My Code22652723easy to understand

in Div2C

I can't understand why not to fill our resulted array with zeroes and printing answer as 1? is there any restriction about our resulted array, that must contain different numbers?

You want to maximize the minimum mux so if u fill the whole array with zeroes the answer will be 1 but u can fill it from 0 to the length of the array so the closest non-negative integer can be the maximum which is the length of the array.

In 739E — Gosha is hunting, The editorial writes "Not hard to prove that in group Y we should throw Poke Balls to Pokemons with greatest u - p." I think that we want to maximize PokeBalls probability when we throw PokeBalls. So shouldn't we throw pokeballs to pokemons with greatest p-u?

In Div1-A or Div2-C Why not to just fill the whole array with the maximum available value which is 10^9-1 and the maximum minimum mex becomes 10^9 ?

You didn't mention anything like : the array(or subarray) elements need to be unique !

What am I getting wrong here ?

"The mex of a set S is a minimum possible non-negative integer that is not in S."

if you fill array with max value your ans will be 0

Oooops , yes thanks.

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public String get_SHA_512_SecurePassword(String passwordToHash, String salt){

String generatedPassword = null;

}