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

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

Привет, Codeforces!

12 января в 12.00 MSK пройдет очередной 285-й раунд Codeforces. Автором задач являюсь я(Савинов Евгений). Это мой первый раунд на Codeforces и, надеюсь, не последний.

Хочу поблагодарить Сергея Кияна(sokian) и Александра Голованова(Golovanov399) за помощь в подготовке и прорешивании задач, Макса Ахмедова(Zlobober) за неоценимую помощь в подготовке контеста, Алекса Фетисова(AlexFetisov) за прорешивание раунда, Марию Белову(Delinur) за перевод условий на английский язык и, конечно же, Михаила Мирзаянова(MikeMirzayanov) за замечательные системы Codeforces и Polygon.

Кстати, сегодня(11 января) у Михаила Расиховича день рождения, давайте поздравим его с этим!

Раунд состоится в обоих дивизионах. Информация о разбалловке будет опубликована перед началом раунда.

UPD1: Будет использоваться динамическая разбалловка. Задачи расположены в порядке возрастания предполагаемой сложности.

UPD2: Разбор задач можно найти здесь.

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

»
9 лет назад, # |
Rev. 11   Проголосовать: нравится -32 Проголосовать: не нравится

It's time is too early in our (Iranian students) timezone because we have to go to school.

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

85 is a holy number for Iranians :D

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

Wow ... Mike's Birthday ... That's amazing ... :]


#include <iostream> using namespace std; int main () { cout << "Happy Birthday Mike ! \\:D/" << endl << "Thanks For Everything !!! :D" << endl; return 0; }
»
9 лет назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

Happy birthday MikeMirzayanov.

BTW it seems like tomorrow will be a busy day. Topcoder SRM 645 will take place 5 hours after the end of this round.

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

Раунд будет в 3 часа дня для меня, главный вопрос придти на работу до или после)

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

    Можно писать на работе, я обычно так и делаю.

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

      Извиняюсь за, возможно, глупый вопрос, но как к этому относится начальство?

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

Огромное спасибо MikeMirzayanov за такие замечательные платформы как Codeforces и Polygon. С днём рождения!

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

Happy birthday MikeMirzayanov.

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

dis like me pls

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

Information about score distribution will be posted just before the round starts.

Why for almost all contests score distribution reveled just before the contest? What happens if author(s) revel it early?

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

Поистине гениально устраивать раунд в 12 часов первого рабочего дня в году

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

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

Weird timing. Cannot participate due to classes. BTW Happy Birhtday MIKE!!

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

thanks :)

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

Happy Birthday dear MikeMirzayanov.

Best wishes, from iran, Hamed

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

The first round in 2015 :)

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

Here in Venezuela Contest will take place at 4:30 a.m T_T i hope my alarm can wake me T_T

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

new year starts , i want to enjoy it as much as possible....:)

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

Are the problems easy or hard?

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

missed contest because of class :(

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

Hey savinov !
You can use this tag "Happy Birthday Mike ":)

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

Score distribution?

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

I'm so happy that I catch the contest. It was a hurry that I went home from the school.

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

In Codeforces rounds, when two or more separate contests are going to be held, the contests numbers are given by separating with comma. How to detect which contest number belongs to which one? e.g.: Today, two separate contests are scheduled for two divisions in round #285 and the contest link is: http://codeforces.com/contests/501,504. Now, my question is which division belongs to 501? is there any general way to know this for any round before its started? I think, MikeMirzayanov could say the exact answer.Thanks in advance.

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

Oh no, dynamic scoring(((

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

Why????????

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

    You should had registered to contest using 'register' link in contest list. Not everybody always participates, so system should know who wants to generate rooms.

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

in first 10 minutes i was 5th...

But now I'm 260th...

Why I can't never solve C???? :(

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

Nice problems! :)

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

It's a very bad idea to give numbers in decimal in D :(

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

What was the aproach to task C?

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

    Since the graph is guaranteed to be acyclic, it is a forest and hence it has a leaf. Find one such leaf v. Its neighbor-XOR-sum is the XOR of a single number (the label of its sole neighbor u), so we know there is an edge between v and u. Now decrement u's degree count and XOR u's neighbor-XOR-sum by v (this means removing v from the forest), rinse and repeat.

    To avoid O(n2) time, store the leaves in a stack/queue. After a first pass through the vertices, you will only add at most one vertex at any given time (if u above has degree two, u itself is added to the stack).

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

    It is similar to topological sorting

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

Как C делать? У меня вот упадет, да и много у кого, мне кажется.

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

How to solve problem D/B ( Div2/Div1 ) . thanx in advance :)

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

      I've used a similar approach.

      However, I could only transform the permutation into a factoradic sequence in a quick way, but not vice versa.

      Any good approaches? Thanks much!

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

        What first comes to mind is a data structure that can find the k-th smallest element stored in it. I used a binary indexed tree in composition with binary search. From what I see after skimming some of the solutions that was a common approach. The total time complexity is .

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

        You can use binary search.

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

      My submission 9414663 used this factorial number system but TLE'd. Is there an implementation that could make my program faster or is it because I used Python (which is slow)?

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

        list.remove is O(n).

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

        You used decimal in your math.factorial(x) line. The trick is to avoid conversion to the decimal system and compute everything in factoradic directly.

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

        Guess how long it takes to compute math.factorial(200000), and repeat this 200000 times.

        Yes, your algorithm runs in at least time. You have to find a faster algorithm.

        On the other hand, my solution got TLE too in Python, so yes, you also need to move to a faster language.

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

Верно ли такое решение к Е?

Подвешиваем дерево за какую-нибудь вершину. Считаем хеши в каждой вершине на пути из нее в корень и из корня в нее. Дальше при запросе перебираем длину lcp бин. поиском. Чтобы зачекать префиксы хешами, находим lca каждой пары вершин и с помощью двоичных подъемов и level ancestor (la) получаем хеш префикса.

Итого ...

Можно заменить lca и la на крутые алгоритмы за O(1), но я в них не верю

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

    TLE? Oo

    Вам так не нравится ? :)

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

    На самом деле можно бинпоиск и двоичный подъем объединить и сделать так, чтобы оно работало за на запрос.

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

Hi,

I find the English version of problem C's description is confusing: " XOR sum of the numbers of vertices adjacent to v ..."

I can only understand it, after look at the Russian version: "XOR-сумма номеров вершин, смежных с v ..."

Seems like google translate did bad job :D

PS: I am out of this round, so I comment here. Good luck for your final rank!

EDITED: The statement should be: " XOR sum of the indexes of vertices adjacent to v ..."

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

    The XOR sum of numbers a1, a2, ..., an is simply a1 ^ a2 ^ ...  ^ an; everything XORed together.

    Although yes, "the XOR sum of the numbers of vertices adjacent to v" might be better phrased as "the XOR sum of the labels of vertices adjacent to v".

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

Хороший контест, жаль слил его, застопорившись на первой задаче :( Очень понравились чужие решения Div-1 A, без всяких Set-ов, через стек/очередь, до которых я не догадался.

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

    я сразу после конца допер до такого решения))

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

Can somebody please explain to me the second test case for C problem? Thanks in advance.

2
1 1
1 0

Note: (From problem statement) ...were the first integer is the number of vertices adjacent to vertex v, and the second integer is the XOR sum of the numbers of vertices adjacent to v...

No idea what second integer means. I do not understand why if both vertex have the same adjacent vertex number then the second number is different.

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

    There are 2 verticles (0 and 1) with the only edge between them, so for zero verticle degree=1 and xor of 1 is equal to 1, for the second — degree=1 and xor of 0 is equal to 0.

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

    There is an edge between vertex 0 and vertex 1.

    so for vertex 0, degree = 1, and XOR sum = 1 (vertex 1 is the only adjacent vertex)

    for vertex 1, degree = 1, and XOR sum = 0 (vertex 0 is the only adjacent vertex)

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

    second integer means the XOR sum of the numbers on the adjacent vertexes, not the number of adjacent vertexes.

    For example, if a vertex 0 is adjacent to vertex 1, vertex 2, and vertex 4, then the second integer for vertex 0 is "1 ^ 2 ^ 4 = 7"

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

    "were the first integer is the number of vertices adjacent to vertex v"

    "the number of vertices" means the amount of vertices, connected to this vertex.

    I think it's a shortage of the translation.

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

Am I the only one that thinks that number of interesting problems in that contest equals 0 :/? Though E was interesting a bit, but also pretty tedious to code, but I didn't find anything interesting in BCD, especially D which was "change decimal to binary and do some Gauss", pls. Sorry to say that.

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

    I have the same opinion.

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

    I found problem Div1-A/Div2-C pretty interesting and funny (maybe because our skills differ too much).

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

    Wow, when writing that comment I expected lots of minuses, because that's what hating posts usually get, but people seem to agree with me :P.

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

      Well, usually when I see some downvoted hating post, it sounds like "I got TL on B, why did you set such a small limit? And I also got WA on C because of overflow, why there are no overflow cases in pretests? And I totally screwed up today, so this contest is awful".

      And today I tried this round, because I've missed live edition; after that I opened comments, saw your message and thought "yeah, he is completely right...". This is the difference between that "usually" and this case.

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

What was the approach for Div 1 C?

Only observation that I could make is following.

For a fixed index i, let us say there exists an index j s.t. if we can make the entire array an valid palindrome by shuffling values of array from index range [i, j], then we can also do the same for any range [i, k] where k > j. This idea can be used to do binary search over j.

But I had doubts about how to check whether shuffling of current range [i, j] can make the entire array palindrome or not?

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

    This, actually, was my exact observation as well. And I have the same question; though I believe I worked out one of the two possible cases..

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

      it can be done without bin_search:

      i = 1
      j = 1
      while(i <= n) {
       while(i > j || !is_it_a_good_range(i,j)) {
        ++j;
        update_set_with_bad_numbers(j);
        update_set_with_bad_numbers(n+1-j);
       }
       update_set_with_bad_numbers(i);
       update_set_with_bad_numbers(n+1-i);
       ++i;
      }
      

      How can we check given range? For every position 'p' in our range:

      1) we increase count[t[p]]

      2) if n+1-p is outside this range, we decrease count[t[n+1-p]] (unless 'p' is a middle position in whole array)

      In std::set let's have numbers such that count[a] is odd or negative (I call them "bad" numbers). A range is good if everything is ok outside range and:

      1) our set is empty, or

      2) our set has one number and count[this number] is positive odd number (it is possible only for odd n)

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

    If you observe more, you would found that there are only twe basic range. Let a[1+k] != a[n-k] and for every i < k, a[1+i] == a[n-i]. So the two basic range is [1+k, g] and [h, n-k]. so you don't need to binary and just iterte over g and h.

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

    I don't understand. For a string 22134 We can rearrange range [0, 2], but not [0, 3]...

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

      You are rearranging a segment, but the entire string should become a palindrome.

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

I guess we can say that the Div. 2 3rd place account I_have_many_girlfriends (which was likely a Div. 2 account) is a cheater (because he has many girlfriends) :P

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

    Which would not be very surprising because one cannot have many girlfriends without cheating on them.

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

I think there is problem about Div1.D and E's time limit. After solved C, I found that the basic solutions for both problems are possible to get TLE. An solution O(n^3 / 64) for C and an solution O(mlogn^2) for E. But the O(n^3 / 64) for C get Ac and O(mlogn^2) for E get TLE. So unfair to someone just as me choose E to solve~

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

кто поможет найти 14 читеров, решивших В? в этом случае, ее стоимость возрастет до 1000 и рейтинг упадет не так сильно))

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

    до этого раунда мне нравилась динамическая разбалловка))

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

Just learnt how reading bignums and asking about j-th bit looks in Java ;

BigInteger x = new BigInteger(in.next());
x.testBit(j);

And in C++?????

Great idea to give them in decimal, that task was surely equally hard to Java and C++ coders.

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

Whenever the system testing is fast, the rating updates are slow! :D Whenever the system testing is slow, the rating updates are fast!

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

epic bug =\ this code passed 7 tests ...

set<int>::iterator it = s.lower_bound(x);
s.erase(it);
upd(*it);
»
9 лет назад, # |
Rev. 4   Проголосовать: нравится -16 Проголосовать: не нравится

thanks savinov :)
your contest has nice problem :)

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

Approach for problem B.

(Explanation from adurysk)

Finding order of a permutation in a factorial representation
You can represent the order of any permutation like this. If a[0...n-1] is the given array, let la[0...n-1] be another array in which la[i] stores number of j such that j > i and a[j] < a[i] now the order of permutation a[0...n-1] will be la[0] * (n-1)! + la[1] * (n-2)! + la[2] * (n-3)! +.....you can see that la[i] < n — i similarly you can calculate the array lb[i] for the permutation b[0...n-1] now sum these two to get lc[i] = la[i] + lb[i] now at some index lc[i] can be greater than n — i, you can avoid this by shifting the carry to the index i — 1 and reconstruct the array c.

Getting permutation C from the lc array.
This part should be pretty easy. Go from left to right. Let us consider the situation in the beginning. At index 0, our value lc[0] denotes that precisely lc[0] numbers are less than our number at current index. So we can directly say that current number will be lc[0] + 1. So if we go to next index, we need to remember this assignment done at index 0. For that we can maintain a set of remaining numbers in permutation of size n. Now we need to find lc[i]^th the number in this set. This way we can extend the approach for any index i > 0.

We can use BIT for maintaining the required set.

Note: By set, I mean a mathematical notation of set, Don't confuse it with set in STL.

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

    what is the intuition behind adding lc[i]=la[i]+lb[i]? even if we add these then it will contain n+1 numbers right?

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

Расскажите, пожалуйста про 23 тест в Div1/C. Очень интересно. З.Ы. много решений упало на этом тесте.

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

    какой-то большой рандомно-пошафленный палиндром с алфавитом из двух букв.

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

What was the approach for Div 1 D?

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

What was the approach for Div 1 D?

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

Wow, dreamoon_love_AA back to red in no time. Congrats!

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

Будет разбор задач?

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

Задачи с легендой про Мишу — это был идеальный контест :)

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

Does anyone have properly commented solution to div1 B (it would be nice if codeforces allowed us to sort searches by the "comment concentration" of code)

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

In almost all solutions of Div.2 D / Div.1 B I see magical operation x -= x & (-x) on integer x. Maybe someone can tell what is the meaning of it? And by the way, what is the data structure used? Where can I learn more about it? For me it doesn't look exactly like a segment tree.

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

What are the detailed aproaches to all questions by the writer?

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

Why no congratulations on the winners like in other rounds? :(

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

Codechef is busy doing Hackercup, I guess. :P Server is down.