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

Автор zloyplace35, история, 7 лет назад, По-русски
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Разбор задач AIM Tech Round 4 (Div. 1)
Разбор задач AIM Tech Round 4 (Div. 2)
  • Проголосовать: нравится
  • +110
  • Проголосовать: не нравится

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

Problem D-div2, B-div1 has a very weird situation, it's like what is the possibility that the given solution fail there must be,, it's just surprising to have such a problem and for B-div2 I think an overflow test in the pretests should exist

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

    Yeah, this is the first time I've seen a non-deterministic algorithm used on CF. I assumed that their problems were always deterministic, so I just thought the problem was impossible and stopped working on it lol. That being said, I didn't actually calculate the probability of success when choosing k random indices, and you could write a program to calculate that probability for you and find the optimal k, so I do actually think it's a cool problem in hindsight.

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

Is this the first time that the intended solution to a problem was a randomized solution ?

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

    I think so. This problem was also solved by many using randomized algorithm. However, the editorial came out and I found out there was a deterministic solution. I was quite impressed. The belief that contest problems did not intend randomized algorithm was still intact.

    I was also wondering what the deterministic solution could be for this problem and I must say I am somewhat disappointed :/ I found the randomized algorithm for this problem quite early but there was always a chance for this failing so I did not submit

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

i don't like it when the same code got WA and AC

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

why the down votes?

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

843C — Переподвешивание дерева

Компоненты, которые крепятся к центроиду, не могут поменять свой центроид

Почему же не могут? Берем второй тест из условия, применяем такой ответ:

6
4 3 1
1 2 3
4 1 3
4 5 7
7 6 5
4 7 5

В первой компоненте центроидом была вершина 2, а стала вершина 3.

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

Excuse me,am I the only one who has some difficulties understanding the editorial?

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

Я вообще не понял разбор div1D. Может кто-то пожалуйста подробнее объяснить?

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

    Насчитаем изначальные расстояния обычной Дейкстрой, далее будем обрабатывать запросы в исходном порядке.

    Пусть пришел запрос на увеличение ребер, пересчитаем расстояния. Введем потенциалы, равные distu, заменим веса ребер на w'i = wi + distai - distbi. Очевидно, что в новом графе все веса неотрицательные (неравенство треугольника в графе), а расстояния до каждой вершины равны нулю.

    Прибавим изменения к w'. Расстояние до каждой вершины не более количества изменений c, поэтому в новом графе можно пустить Дейкстру подсчетом за O(N + M + c).

    Чтобы получить исходные расстояния, нужно прибавить к расстояниям в новом графе потенциал, т.е. newdistu = dist'u + distu. Итого получилось , где C — суммарное число изменений.

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

can someone explain Sorting by Subsequences more clearly and what is the maximum limit of cycles in subsequence . and thanks in advance _/_

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

    Let b1, b2, b3, ..., bn be the sorted version of a. Fix x, 1 ≤ x ≤ n. Let x' be such that bx' = ax. Using DSU, merge the two sets containing x' and x. Do this for all x, and then count the number of disjoint sets.

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

This Might sound alittle stupid but where did the 2^k — 1 come from in div2 B Thanks

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

Hedgehog? Bamboo? Anyone care to explain?

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

    we need to convert each child of the centroid to star graphs hence i guess bamboo means chains and hedgehog means star graphs.
    Bamboo makes sense for chains but how is hedgehog related to star graphs?

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

      Because our friend the hedgehog

      has many spines pointing outward, so she looks like a star graph.

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

      I still don't understand how to do that; how to transform each 'child' to a star graph? Wouldn't the centroid children change?

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

      Could you explain to me why do we have to look for centroids whereas we could transform whole tree to "hedgehog" star graph by simply transforming it first to "bamboo" and then to star graph using exacly 2n operations?

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

Please upload the code for the model solutions as well. I understood the logic for Div 2 — C but it is hard for me to implement it.

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

can anyone please explain 843B(interactive LowerBound) , i couldnot understand it at all!

  • »
    »
    7 лет назад, # ^ |
    Rev. 6   Проголосовать: нравится +10 Проголосовать: не нравится

    Let's suppose that we are following the approach of the editorial: we ask for the starting position plus 999 random points. Among all the answers to our queries, we get the greatest number less than or equal to x and we forward-iterate it 999 times.

    For simplicity, fix n = 50000 and let's suppose that the answer is in a position such that it has at least 998 elements to its left (that is, there are at least 998 numbers less than the answer). We can see that if we have asked for at least one of the 998 numbers that are immediately previous to the answer or for the answer itself we are done, since we will iterate 999 times to the right and we will find the answer.

    If we ask a question the probability of getting a number that is not the answer nor any of the 998 "good" numbers is . However, we are going to ask 1000 questions, and the probability that all of these 1000 questions are about "bad" numbers is 0.980021000 = 1.7 × 10 - 9, which is very small. The probability to answer correctly 200 tests is (1 - 1.7 × 10 - 9)200 ≈ 1, which is ultra-high. This probability can be even greater if you make sure that you never ask for the same point twice.

    Finally, note two things: if the answer has less than 998 elements to its left then we will find it with probability 1 given that the first query is precisely the starting point. Also, the probability formula described above gives higher and higher probabilities as n becomes smaller, so you can be sure that this approach will work.

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

Regarding div2 D (div1A — 843B — Interactive LowerBound) apparently I am getting WA when I use rand() and I am getting AC when using 78*rand()%MOD+rand() (or any sort of strange transformation. Why is that? Isnt rand() random enough?

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

    rand() is bounded by RAND_MAX which while it is guaranteed to be at least 32,767 on any standard library implementation, and a size of 2,147,483,647 or similar is relatively common it doesn't change the fact that the guaranteed maximum is 32,767 which is smaller than 50,000. If we were to place the solution in the ~17,000 where the random sampling would not reach, this would produce an WA.

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

    Also, WA on tc 107 if you use random_shuffle once, and AC if you do it twice.

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

How is the checker for D2E/D1C implemented? Link/cut tree?

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

    Centroid decomposition with FFT can be used to calculate count of each distance since maximum distance is n - 1 (cnt[i] is a number of pairs with distance between them equals to i). Then check .

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

      Actually the sum of squares can be calculated with a single DFS in linear time. You just need to maintain the size of each subtree, the sum of distances from root of current subtree to all the vertices in it and the sum of squares of distance from root of current subtree to all the vertices.

      We've used approach similar to Dynamic Connectivity Offline solution to check correctness of sizes in .

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

problem 2E/1C: I'm still inquisitive but I can't finish the "exercise" myself, is there additional explanation?

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

How to solve DIV-2/C using DFS?

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

    You have to find all connected components in a graph, where edges are (original position in the array, position in sorted array). For example:

    10

    3 7 10 1 9 5 4 8 6 2

    After sorting we have 1 2 3 4 5 6 7 8 9 10.

    You have edges (4, 1), (1, 3), (3, 10), (10, 2), (2, 7), (7, 4); (5, 9), (9, 6), (6, 5); (8, 8). So we have 3 connected components, it's easy to see we can't have more than that. You can find the number of components using DFS.

    Refer to my code for details 29740082

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

      Thanks very much for this explanation. It is easier to understand than in official solution.

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

In Div-2 B why you didn't say that the subsets with different order are considered different ? I thought that {1, 2} is the same as {2, 1} :"D

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

Div2 843D — Interactive LowerBound I had exactly the same solution in mind after I've solved A, B, C.

I sat for one hour during contest convincing myself that there should be a deterministic solution because it's CodeForces.

Good to know there are problems on CodeForces which require randomized algorithms to solve,

P.S. Proposal: Making special CodeForces Round devoted to randomized algorithms.

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

Guys, how to pass the 107th test on Div2 D? I've got no idea. Pls, help...

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

Я не очень понимаю механизм определения множеств (div. 2 B). Может кто-нибудь указать конкретно, какие множества есть в этом примере? 2 2 1 1 1 1

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

    Обозначим элементы как 1, 2, 3 и 4. Множества : (1), (2), (3), (4), (1, 2), (3, 4), (1, 3), (2, 4)

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

      А почему не (2, 4) или (2, 3)? Это же тоже множества с одинаковыми элементами, к тому же (2, 4) ещё и второму условию удовлетворяет, которое говорит об двух любых клетках в одном столбце.

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

        Не думаю, что элементы 2 и 3 лежат в одной строке или столбце.

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

        Конкретно в этом примере рассматриваются множества {1}, {2}, {3}, {4}, {1, 2}, {3, 4}, {1, 3} и {2, 4}.

        Вообще, рассмотрим какое-то множество, которое удовлетворяет условию задачи. Кроме того, что все его элементы одного цвета, мы также можем сказать, что ВСЕ они лежат на одной линии (строке/столбце).

        В самом деле, если элементы 1 и 2 этого множества лежат на одной строке, а какой-то элемент 3 в этой строке не лежит, то элемент 3 не может быть в одном столбце и с элементом 1, и с элементом 2.

        Это так, ведь по условию "любые 2 элемента множества лежат в одной строке/столбце".

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

          Мдааа, на контесте я решал совершенно другую задачу. Я подумал, что прямоугольнике ДВА типа множеств: там, где все одинакового цвета и там, где две клетки в строке/столбце. Но теперь при этом взгляде вытекает следующая проблема: исходя из второго условия, получается множество должно состоять из ДВУХ и более клеток, иначе как мы сможем проверить правильность этого условия? Почему мы тогда выделяем единственное число как отдельное множество? Ведь мы не можем проверить второе условие для него.

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

            Если множество состоит только из одной клетки, то все его элементы лежат в одной строке/столбце и имеют одинаковый цвет.

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

Помогите, пожалуйста!

Я пытался решить задачу C (Div.2). Вот моя программа: http://codeforces.com/contest/844/submission/29760854. Но моё решение оказалось слишком медленным.

Я попытался это исправить, но ничего не вышло. (http://codeforces.com/contest/844/submission/29775215 ).

Объясните, пожалуйста, почему моё решение такое медленное, и как это можно обойти. Неужели рекурсия — единственное, что помогает в этой задаче?

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

Help me, please!

I tried to solve problem C. Here is my program: http://codeforces.com/contest/844/submission/29760854. But my solution was too slow.

I tried to fix it, but nothing happened. (http://codeforces.com/contest/844/submission/29775215 ).

Please, explain me why my my solution is too slow and how to fix it? Is recursion the only thing that helps to solve this problem?

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

Div 2 C/ Div 1 A: Why "We can split this permutation into simple cycles. The subsequences in the answer are subsequences formed by these simple cycles." ? Can someone prove it?

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

    Assume we have a subsequence containing the element in position i in the original sequence. Let j denote the position of this element in the sorted sequence. Then to sort the sequence this subsequence must also contain j since i has to be moved there. Now we repeat the reasoning for j and so on and we eventually get a cycle.

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

bad solution

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

Can someone explain how to get star graph from a chain graph using centroid decomposition? As I understand, if we apply CD as it is to the chain graph, we get something similar to binary tree with log(n) levels, but not a star. Help, please! Thanks in advance :)

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

    I think that there are graphs which cannot be changed into start. Degree of centroid in tree is unchangeable so if centroid don't have degree equal n-1 than we would never get a star.

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

      Now I see They are not changing into a star. They are changing into centroid with stars.

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

I've made an experiment for 843B task (LowerBound).

It can be solved even like this :)

http://codeforces.com/contest/843/submission/29779241

http://codeforces.com/contest/843/submission/29779421

http://codeforces.com/contest/843/submission/29779484

I suppose the tests are chosen not to find the solution using any deterministic distribution.

That's why non-deterministic algorithms are not very good. Probability is an uncontrolled evil in this case.

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

Finally... It's back

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

Help please! For Div 2 D, I am getting WA on test 62. I am using mt19937 for generating random numbers. Code

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

Anyone can elaborate a bit more on Div2 problem E?

When it says "A centroid-vertex remains a centroid during such process. If we have two centroids in a tree, the edge between them couldn't change."

Is it a pre-requisite knowledge one should know in order to solve this problem; OR Is it a constraint / property of the tree we have to follow in the process in order to solve the problem?

If it's the latter, can someone explain why and a brief proof on it...?

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

    I was wondering this problem too...Can someone give an answer please... If the tree has two centroids,if I change the edge between them,must the sum of squared distances between all pairs of vertices change to greater or it's not good enough...?(

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

Can anyone explain the last line of 843D tutorial please?! I can't understand how the dijkstra must be implemented!

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

DIV2 B.. using pow function (C++ stl) result in Wrong Answer on Test case 18... instead, use an array to store the powers of 2 (upto 50 (2^50) ).