Напоминание: в случае технических проблем любого характера, вы можете использовать m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

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

Автор huzecong, 10 лет назад, перевод, По-русски

Всем привет!

Приглашаем вас принять участие в Codeforces Round #248, который начнется в субботу 24-го мая в 11:00. Раунд будет проходить в обоих дивизионах. Обратите внимание на крайне нестандартное время проведения раунда.

Задачи были подготовлены zhonghaoxi, wyx528 и мной. Это наш первый раунд Codeforces, надеемся, что он пройдет хорошо.

Большое спасибо Gerald за помощь в подготовке раунда, а также спасибо colin и MSTyoda за тестирование раунда. Традиционно благодарим MikeMirzayanov за создание удобной платформы для проведения соревнований.

В дивизионе 1, это будет 500-1000-1500-2000-3000, в дивизионе 2, это будет 500-1500-1500-2000-2500.

Надеюсь вам понравятся задачи! Желаем вам удачи и удовольствия от решения задач~

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

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

Actually, it takes place on Saturday, not Sunday :D

Pity that I won't be able to participate, I have another competition going on at that time. An onsite one... nothing I can do.

Besides that:

wow
such early
much announcement
very Chinese

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

First thanks for preparing this round I know it take a lot of efforts to do problem set for both Divisions
Second why this statement is always written on all the rounds
Score distribution will be published before the contest
or sentences with the same meaning
It seems that the first person wrote this sentence and all follow him without given reason :)
I think while you preparing the problem set you know the position of each problem.
but anyway when you announce the Score distribution a little bit time before the contest it create a something of a curiosity all the time starting from announcing the round till announcing the Score distribution and when we see score distribution we can Rest In Peace.

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

    There is actually a reason... We still have to confirm the difficulty of the problems, to make sure we weren't wrong.

    And in my opinion score distribution is only a subjective and relative measurement of difficulty, so it doesn't say much about the actual difficulty of the problems.

    But anyway, we apologize for any inconvenience caused, and will try to put up the score distribution ASAP.

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

nice time for me:))

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

Are huzecong and wyx528 a pair of lovers?>_<

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

orzzz... Hoping to see problems without too hard data structures

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

This post should appear in the home page so everybody can find it easily.

[update] the post is in the home page now, thanks :)

I love contests in that time of day , I wish that this contest will be interesting

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

Contest kicks off at 8.00 am in my country. Coding is always a good activity to begin your day.

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

Chinese round again~

orzzzzz

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

marriage!

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

Nice time for me, Happy to see the problem setter from my hometown :)

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

This Score distribution not standard :)

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

3000.. How difficult div1-E will be..

And in my memory, almost all of Chinese round, nobody can solve E during the contest >_<

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

No 1000-score problem [again]?! Is this a new method of scoring?!

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

Hope,I can give better look to my rating graph today :D btw,Best of luck ... !!! :)

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

Kill la Kill, Clannad, Kami-sama hajimemashita, angel beats, kyoukai no kanata, white album :D

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

Chinese again! :(

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

omg the problem set is harder than Bruce Lee's punch X_X

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

How interesting...

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

Del

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

Разве компилятор Microsorf C++ 2010 должен выдавать ошибку компиляции при warning'ах? Все время, пока я его использовал, он спокойно считывал при помощи scanf, а сегодня почему-то выдал CE. Посылка: 6700285

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

    Причем тут scanf?

    error C4716: 'recalc' : must return a value

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

How to solve A div 1 / C div 2?

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

    I submitted a ternary search.

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

    Consider every page: the best strategy is to merge it to the median of all the page next(in the operation sequence) to it. Choose the best answer. I pass the pretest but I am not sure it can pass all the test.

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

      Can you prove that we should merge it to the median?

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

        The median is the solution to finding a 'center point' when the distance metric is abs. This also counts in multiple dimensions, e.g. if the 2d metric is abs(x0-x1)+abs(y0-y1) etc.

        You can prove it by assuming another solution is better and then noticing that moving a bit closer to the median improves the answer. Hence only the median can be optimal.

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

    Consider each of the m numbers in your sequence, what will you safe by changing it to something else?

    If the sequence is "1 2 3 3 1 3", 3 is in |2-3|,|3-3|,|3-1|,|1-3| = 5. Hence if we change it to x, we safe 5-(|2-x|+|x-x|+|x-1|+|1-x|). To get the maximum value of the amount saved, just pick x to be the median of 2,1,1.

    Now how expensive is this? There are m numbers, each of which could have nearly m neighbours, so is it m^2? No, because we only consider each pair of neighbours twice, so the total running time is O(m) or O(mlogm) if we pick the medians by sorting.

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

What is the approach to solve Div2 Problem C?

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

На чем ломали DIV1-A помимо использования set вместо multiset или sorted vector?

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

    Меня взломали из-за того, что я добавлял X в вектор чисел, которые стоят рядом с X

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

    В самом начале нужно заменить все подряд идущих одинаковые числа на единственное.

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

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

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

        В самом начале, думаю, имеется ввиду до начала алгоритма.

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

        Решение, которое добавляет "X в вектор чисел, которые стоят рядом с X" (см. комментарий выше) :)

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

Tricky Div1 A is tricky :'(

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

This was way harder than usual ( at least for me ). Although , very nice problems. Big plus for the authors and waiting for your next contest !

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

а кстати, в А див 1 кто-нибудь писал тернарник? ну т.е. перебираем число, и для него тернарным поиском ищем оптимальную замену?

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

I would say that while reading names in the problem statement, It was feeling like playing a tongue twister game. Chinese names are too difficult to pronounce in mind :).

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

Why my solution got Wrong answer on pretest 2? 6700945 UPD: found error x.x

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

Tricky contest...

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

Баг или КФ ко мне сегодня добрый?:)

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

Два раза пытался перечитать условие C Div1, но текст выглядел для меня примерно как тесты на логику:

. Если запырку отравить, то она сразу начнет пускать пузыри. если запырка пускает пузыри, то она была отравлена; если запырку не отравить, то она не будет пускать пузыри; если запырка не пускает пузыри, то она не отравлена.

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

Oh, sometimes you're clever enough to be very stupid :(
I used BITs instead of simple partial sums in B and so I've no idea if my code will pass TL. UPD: And it passed! I LOVE CF!!! Anyway, great problems, thank you!

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

    Can you explain a bit about the two solutions?

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

    There's popular Chinese Internet slang that goes "no do no die", which means if you look for trouble then you're definitely in trouble.

    This is especially true in competitive programming. It's best to keep solutions simple.

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

      Yeah, I try to do it. Unfortunately, I don't succeed always and that's one of the reasons I fail contests sometimes.
      But when it's needed to change elements of an array and calculate sums of its segments the last thing you think about is naive partial sums.)

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

      Click Zan!

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

Я решал А с помощью n сортировок (сортируем все числа, которые идут вместе с 1<=i<=n числом, берём медиану и пересчитываем значение). Возможно даже зайдет.

Как решали B?

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

    B, по-моему, проще A. По крайней мере, думать надо меньше.
    Будем, например, для каждой строки и столбца хранить массив частичных сумм, дабы быстро считать суммы на отрезке.
    Первый тип запросов обрабатывается за O(N + M) на запрос тривиально.
    Второй делаем так:
    Находим длину максимального отрезка из единиц слева и справа от клетки. Потом идем вверх и на каждом шаге сначала обновляем эти длины, а потом релаксируем ответ исходя из них. После этого повторяем то же самое вправо, вниз и влево.
    Это вкратце.

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

      Я пытался делать то же самое, только считая длины деревом Фенвика. TL.

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

        На самом деле во время раунда я тоже послал Фенвика (коммент чуть выше) и, хотя оно прошло претесты, наверняка тоже будет TL. Эх..

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

        Можно обойтись одномерным деревом, т.к. при сдвиге указателей можно считать сумму на прямоугольниках размера 1*A или A*1.

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

          Можно решать вообще без деревьев и префиксных сумм, просто будем для каждой ячейки хранить позицию ближайшего нолика с каждой стороны :) Пересчет на запрос будет за 4 * N.

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

        с set-ом зашло за 500мс

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

How to solve D?

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

pending system testing ................

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

Great questions! But super tough! I, for one, am looking forward to the editorial ;)

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

For the first time, I have to write a test generator for B to make sure that it won't get TLE.

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

Locked my problem too late, only to find 12 hacked solutions on Div 2 Problem A. What is the highest number of hacks for that problem? Any idea?

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

At the end of the contest I felt that this contest must not be a usual contest.
When I see the home page I see Chinese writers.
I get the reason ... :)

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

awesome set of questions... if possible anyone plz explain the approach of Div2-C

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

http://codeforces.com/contest/433/submission/6692939 Arrays.sort? А что там внутри??

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

Towards the end of the contest I tried to hack sas4eka's solution for problem A (Div1) by trying to make it get TLE (it seems that for each pair of consecutive positions it iterated through all the occurrences of the first number in the pair, so a test case like N=M=100000 and 1 2 1 2 ...... 1 2 should make his solution get TLE). Since the test case was large, I wrote a generator and wanted to upload the generator (after selecting generated input in the Hacking interface). I selected my generator's source file and then I pressed "Hack". Instead, I got some error that either a test case or the generator must be specified (or something similar). I tries setting some generator parameters and pressed Hack again — nothing happened this time either. Then the contest ended and my hack was not submitted. Perhaps I did something wrong, because I usually do not try to hack other's solutions during the contest and I am not familiar with the Hacking interface. My question then is : can I try to hack other people's solutions outside of a contest ? (just for practice) If not, then how can I become familiar with the Hacking interface so that next time I know what to do? (because it seems that the interface is not as straight-forward as I was expecting it to be). And I would rather not waste time from a real contest for this. Note that in TopCoder it is possible to challenge solutions even in the Practice room, so maybe something similar should also be possible in Codeforces? (in case this is already possible, then please just ignore my question)

Later edit: The solution I was trying to hack did get TLE in the end, so I guess my hack would have been successful... had I known how to properly submit it.

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

    As far as I remember there are two tabs, one for submitting usual test (in text form or by specifying a path to file with a test) and another one for submitting generator (path to generator [and some parameters to pass to generator]). Perhaps, you wrote something in the first form (or had selected file there) before to switch to the generator form.

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

      Hm.. yes, I actually did :) At first I didn't notice the 2 tabs and I selected the generator code where the upload of a test file was. Then I noticed the tab was called "manual tests" (or something similar) and I selected the other tab (for generated input), where I did what I said in my post. I wouldn't have imagined that whatever actions I did in the first tab would still be considered when I switched to the other tab. This is non-intuitive to me and only enhances the idea that one needs to first be sufficiently familiar with the Hacking interface in order to use it properly — which is bad, given that we seem to only be able to access that interface during contests.

      Thank you for your answer.

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

    You can practice hacking while participating out of competition in a Div2 contest.

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

      Thank you for your answer. I thought about that myself, too. I think I will do just that in one of the future Div2-only contests. However, if I were a Div2 contestant, that would leave me with no way to practice hacking outside of competition.

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

        Hi, just a friendly reminder that Testing Round will be held today for you to practice hacking solutions. Hope you get notifications for comments :-)

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

What is up with Time limit exceeded on test 46 for Java solutions on Div2-B ?

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

    If i'm not mistaken, Arrays.sort(a) in Java 7 for primitive types runs in O(N^2) on worst case (quicksort with selecting median as pivot).

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

Why does Div 2 Problem C have the same point with Problem B? The successful submission rate is 80 to 1066. I once believed points are distributed using the complexity of the problems, I guess not.

Another ironic part is that Problem A with just as many correct submission with Problem B has 500 points.

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

    My opinion is that C has rather difficult algorithm to think of, while B tests you whether you know the proper sorting algorithm for the problem or not. (Note that I didn't solve either and I'm not sure I have the correct algorithm for B; handling the sorted query needs to sort by counting sort?) Both are relatively obscure for an average Div2-er.

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

      Problem B doesn't require any special technique other than understanding cumulative sum. What I did was compute the cumulative sum of the unsorted array, then sort the array and compute its cumulative sum. The rest was just input and output.

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

    For problem C (DIV 2) Only 59 got accepted after system test and for B it is around 1000. Still both have same points. Is there any chance of change in points distribution now?

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

Cнегопад

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

loved this contest!! I have now many things to learn in this contest's tutorial.
But "wow!!" for the character names. :D

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

#define int long long is evil

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

Can anybode explain me this pretest on C div2 (A div1)? Why the answer is 7?

5 10

2 5 2 2 3 5 3 2 1 3

Thanks.

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

Java is evil , during contest same solution of problem B(Div2) got TLE in java 6692351 but in c++ , 326ms 6701333

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

    Yes. Java Arrays.sort() is O(N^2).

    EDIT : Only for primitive type array

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

      Arrays.sort() uses a merge sort, so it is O(n log n).

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

        See the documentation of Arrays class

        Implementation note: The sorting algorithm is a Dual-Pivot Quicksort * by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm * offers O(n log(n)) performance on many data sets that cause other * quicksorts to degrade to quadratic performance, and is typically * faster than traditional (one-pivot) Quicksort implementations.

        So in some set it can be O(n^2)

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

          But that requires a very evil problemsetter that targets Java specifically...

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

            It's just coincidence may be

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

              It cannot be coincidence. Quick sort is guaranteed to be O(n log n) with high probability , which means the chance of running O(n^2) time converges very quickly to 0 as N increases (even faster than inverse exponential growth[1/2^N]). It must have been a designed input. I really hate such behavior ...

              Exactly the same thing happened for pascal programmers who copied sample quick sort procedure in FPC compiler: See This post (in a Chinese forum) . However zhonghaoxi said they were using random generator.

              UPD User 2333333 is the one who submitted that input instance, though it looks quite normal, there is a previous one got generator compile error and I opened the protocol and it says:

              The hack uses generator
              hack.java:464: error: cannot find symbol
                      new Thread(null, new Java7QuicksortKiller(), "", 128*1024*1024).start();
                                           ^
                symbol:   class Java7QuicksortKiller
                location: class hack
              1 error
              

              And that's why this is happening... Such things are so disgusted, trying to attack a certain language's bug

              Correction: test 45 is target to median pivot sort algorithm. (Many pascal solution fails on test #45) This is a well-known input to hack "standard" quick sort. But Java7QuicksortKiller ... so evil WTF

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

                > Such things are so disgusted, trying to attack a certain language's bug

                And why exactly is that bad? The problem statement does not seem to exclude hard cases. You have one problem statement and plenty of tools (programming languages) to choose from. There is no one perfect tool. Learning the weaknesses of your tools, and how to circumvent them, is essential if you want to use the tools efficiently.

                Specifically in Java, not only you can use a double-pivot Quicksort for primitive types, you can also box them and utilize Timsort for objects which is guaranteed to be .

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

                  Hi Grand Master :D

                  Do you have any idea on why the quicksort in the java library is not randomized?

                  And why it is not possible to utilize Timsort on primitive types?

                  And why it is possible to shuffle a list of objects but not and array of primitve types?

                  Thanks in advance.

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

                  ====================================================================

                  Disclaimer: Note that I'm not anywhere close to a Java expert.

                  As I understand it, library quicksort is optimized for the general case (not the corner cases). Using randomness of any sort would slow it down in the general case. Timsort, on the other hand, is stable, which can come in handy for objects but is useless for primitive types. For an additional bit of reasoning, see here and here.

                  To use Timsort on primitive types, you can box them into their respective wrapper classes. The same goes for shuffling. The language inherently does not allow using generics on primitive types.

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

                  Thanks for the explanation and the links.

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

                  That hack brought down over 80% of Java solutions, do you think it is a good thing or not? Personally I never support it

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

                  =============================================================

                  It may be seen as unfair, in the sense that a test targets a particular inefficiency of a particular tool. Indeed, some but not all of the participants expect challenges to be "pure", in the sense that once you think of the right solution, the implementation should not require much tweaking.

                  It may be seen as fair, in the sense that there are no artificial indulgences for users of particular tools. As far as I understand, every other tool does not have a problem with that test. If so, it's a problem with the tool.

                  Personally, I stick with the latter argument, bearing in mind that the particular inefficiency of Java is so easy to circumvent (boxing + Timsort).

                  The important part is that it's a learning opportunity for the authors of these over 80% solutions.

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

                Such things are so disgusted, trying to attack a certain language's bug

                I am not sure if this is your intent, but your comment sounds as if you are accusing someone who just followed the rules to score as much as possible.

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

    This is a well known problem with java when you sort a primitive type array it uses quick sort which will result in O(N^2) runtime on some specific cases. This had been discussed on many posts on codeforces before

    http://codeforces.com/blog/entry/4827 http://codeforces.com/blog/entry/7108

    The solution is to make your arrays of the class type not the primitive type, i.e int -> Integer, long -> Long. The JVM will use merge sort instead of quick sort in this case.

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

      Thanks , I will take care of this from next time.

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

      What? Doesn't the quicksort use a median selection algorithm that makes it pretty difficult to find an O(n^2) sequence?

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

        Well there are already some generators that were posted on codeforces. Check the links in my comment.

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

        No

        And it is not only difficult to find array on which quick sort with median will work square time, it us outright impossible

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

          Right, I guess I meant "median approximation algorithm" such as "median of three".

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

    Once Again disappointed by the Java standard library :(

    I had the same problem. It seems The quicksort implemented by Arrays.Sort is not randomized ;(

    I had a "time limit exceeded" and solved it by adding a single shuffle (using the fonction below) before calling Arrays.sort and now i have 120ms. u_u

    // Implementing Fisher–Yates shuffle static void shuffleArray(int[] ar) { for (int i = ar.length — 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } }

    RANDOMIZATION IS A MUST AGAINST EVIL PROBLEM SETTERS è_é just kidding ;)

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

Судя по количеству решивших А, B и С (Div.2), В надо было лучше дать 500, чем 1500.

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

My position is 79 on the final standing & I need 114 more to be purple...

Please update it quickly... :(

UPD: I can't... :(

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

А можно решить див2B без дерева отрезков?

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

In Problem A, DIV 1, when you merge page x to y, so you copy the content of page x to page y also. Thus we will be able to find the answers on page x, also.. untill and unless we remove actually remove that page, then we will have to turn less number of pages and answers will change.. Thus th eline ", all elements in sequence a that was x would become y" in the question statement is ambigous with the description. I coded my solution assuming that if we merge page x to y, the will be able to find answers of page X on both page X and Y and thus failed.

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

    That sentence stated exactly how a merge affects sequence a. Since the answer depends solely on a, to me this statement can not be ambiguous.

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

      Anyway, keeping answers on both x and y will make the question more interesting and its solvable with a similar approach.

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

      I agree that it is not ambiguous, but it would have been much better if the problem statement said “she would move” instead of “she would copy.” It confused me first, although I finally assumed that it was just a suboptimal choice of the word and did not ask for clarification.

      By the way, I enjoyed the contest, thank you for the hard work!

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

May be I tell you some not very popular thought, but

Why did email invitation come in the very deep night between Friday and Saturday?

Shame on me not to visit codeforces frequently, but ...

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

very lucky to get #1 :)

After those bad days breaking up with girl friend, seems I can finally walk out of it and training for world final :)

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

thanks, i was happy with contest

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

What means Let_us_play_CF?

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

I tried to implement problem Tachibana Kanade's Tofu and got TLE with MSC++ Compiler. I tried to resubmit it with GNUC++, it got AC >_<

http://codeforces.com/contest/434/submission/6710299

http://codeforces.com/contest/434/submission/6710309

As I remember, in some problems, MSC++ is faster than GNUC++, some others, GNUC++ is faster than MSC++.

Luckily, I couldn't solve this problem while competeting ^_^, if not, the contest would end with many regrets ^^.

Anw, thanks for nice problems : D

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

Hi all. Could you please describe why I'm getting TLE on this? (Problem B Div 2) It's confusing for me because the code passes the 5th test with n = m = 10^5 but it gives TLE on test 46 whose parameters are : n = 88888, m = 1; Here's my submission Thank you.

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

    The problem is in Arrays.sort implementation in Java. It is vunerable to anti-quick-sort test. You should random shuffle the array before sorting it.