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

Автор CherryTree, 12 лет назад, По-русски

Hi everybody!

A new kind of contest starts today at HackerRank. The contest is named "Daily Challenge".

Each day you get to solve a problem, the difficulty increases as the week progresses. You have a weekend to solve the final problem and there will be five problems in total.

This time, I'm a writer of this contest, so I invite everybody to participate. After the contest, there will be an editorial on HackerRank.

Now the contest has started and you have about 20 hours left to solve the first, the easiest problem.

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

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

Seems like login through Google is broken

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

Is there going to be a "challenge" problem? I mean, there are usually lots of people who solve all the tasks in long contests, especially when full feedback is available. Or maybe some tiebreaking rules?

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

Constraints in task C are crazy :) How to solve it?

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

Мало ли кому интересно будет решение по задаче Randomness без хешей.

Авторский разбор: https://www.hackerrank.com/blog/w1-randomness

Заведем сет отсортированных лексикографически суффиксов. Так как у нас всё рандомное, LCP'шки будут маленькие, поэтому компаратор используем самый простой: тупо сравниваем символы. Эмперически можно проверить, что максимальная LCP'шка будет ~8, для уверенности возьмем число 10.

Ну а дальше всё просто, тогда получается при изменении символа мы должны удалить 10 суффиксов из сета, поменять символ, добавить 10 суффиксов, при этом пересчитывая ответ, используя значения lcp'шек с соседними элементами в сете.

Получается что-то типа O(N * lg(N) * MAGIC + Q * lg(N) * MAGIC2) с O(n) памяти, где за MAGIC мы взяли 10. Код: http://pastie.org/private/81pidkdrdeynayxvfncaa

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

When the system test for the last problem will begin?

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

Can somebody describe his 140-pt solution to BST Maintenance?

Mine is based on centroid decomposition, but I have seen a lot of non-similar ideas in the solutions.

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

    My solution is based on heavy-light decomposition. Let's build the final binary search tree, we can do it in O(n log n), and build heavy-light decomposition for it. Then we will add vertexes one by one. Suppose we are adding vertex u at the current step. How to calculate the distances from u to all previous vertexes? For each old vertex(v) it will be distToRoot(u) + distToRoot(v) — 2 * distToRoot(lca(u, v)). So the most difficult part is to calculate the sum of distToRoot(lca(u, v)) for all previous vertexes. It will be the sum of the sizes of subtrees for all vertexes on the path from root to u(actually except u and root). We can do it with heavy-light decomposition and segment tree for sum, with updates on the segment.