Автор awoo, история, 5 лет назад, По-русски

Привет, Codeforces!

В 22.08.2019 17:35 (Московское время) состоится Educational Codeforces Round 71 (рейтинговый для Див. 2).

Продолжается серия образовательных раундов в рамках инициативы Harbour.Space University! Подробности о сотрудничестве Harbour.Space University и Codeforces можно прочитать в посте.

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Роман Roms Глазов, Адилбек adedalic Далабаев, Владимир vovuh Петров, Иван BledDest Андросов и Максим Neon Мещеряков. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

Удачи в раунде! Успешных решений!

UPD: Так же от наших друзей и партнёров из Harbour.Space есть сообщение для вас:

Привет, Codeforces,

Мы открываем новый кампус в Бангкоке, Таиланд!

Мы рады представить стратегическое партнерство между Harbour.Space University и University of the Thai Chamber of Commerce – совместная работа, возможная благодаря B.Grimm.

После 3 успешных лет в Барселоне, с уникальной образовательной моделью, основанной на активном обучении предпринимательству, технологиям и дизайну, а также на самом выдающемся академическом и профессиональном сообществе на планете, мы готовы привнести революцию в наш новый кампус в Бангкоке, Таиланд.

Стипендии для нашего кампуса в Бангкоке полностью устраняют барьер между исключительными талантами и современным образованием: они покрывают не только всю плату за обучение, но и расходы на проживание, а, кроме того, они предоставляют студенту ценный опыт как учебы, так и работы в Harbour.Space University.

Уникальные возможности доступны для самых блестящих студентов из любой точки мира! Наши стипендии — это больше, чем финансовая поддержка – это порталы из вашего прошлого в ваше будущее.

Если вы заканчиваете или уже получили степень бакалавра, мы ждем ваших заявок на получение полностью финансируемых магистерских стипендий по ссылке ниже.

Подать заявку→

Поздравляем победителей:

Место Участник Задач решено Штраф
1 pekempey 7 235
2 hehezhou 7 235
3 TadijaSebez 7 238
4 Barichek 7 241
5 FurryChina 7 247

Было сделано 467 успешных и 688 неудачных взломов.

И, наконец, поздравляем людей, отправивших первое полное решение по задаче:

Задача Участник Штраф
A vintage_Vlad_Makeev 0:01
B Dalgerok 0:04
C kmjp 0:12
D KenMuse 0:13
E AkshajK 0:10
F AnotherRound 0:07
G danya.smelskiy 0:26

UPD: Разбор опубликован

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

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

This may be the first contest for me after getting purple.Hope that I won't drop to blue. :D

I hope that the problems will be nice and easy to understand.

Wish all of you good luck && high rating!

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

Educational #71 ^_^

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

let's hope that it won't be like the last educational round

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

Спустя сорок ЕРов они станут рейтинговыми для всех

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

    А спустя еще 40 — появится div0 специально для едуков.

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

Hope that problems will be interesting and the problems will take some time to develop logic. Then we can have a nice contest also fewer submission and no queue.

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

I hope the problems be easier to understand not like round 70

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

I hope taht the problems be easy to understand not like round 70 X)

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

Почему анонсы educational раундов всегда пишет awoo? Остальным тоже вклад нужен)

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

Can I change my color?

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

    to green lol

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

      Simple trick: Do one wrong submission and quit.
      If you do this for next few contests, you will even reach grey.
      Good luck :)

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

        There is better method to solve a problem with lots of wrong submission, and make lots of unsuccessful hacks to decrease your point. This is more efficient. PS. My color will change to blue after few hour

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

          But I meant my method is simple, ofc there are many other methods like yours.
          Have a nice day :)

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

    why somebody always dis me are everyone want‘t be better? or what wrong with me

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

Why the answer in the first test case of problem C is not 86 = 14 * 5 + 8 * 2?

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

The problem set was real nice.

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

Why so many tests??? Especially F???

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

A much more friendly Educational Round. :)

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

What was testcase 5 on problem B? Been scratching head over all contest but couldn't debug it.

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

    Your logic behind calculating the modulo of the number of ones is wrong. It is not necessary that the number of ones is divisible by four for a valid sequence of transformations to exist.
    Here's an example:
    1 1 1 1
    1 1 1 1
    1 1 1 0
    1 1 0 0
    you can apply the operation at:
    1 1
    1 3
    3 1
    2 2

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

Did anyone solve C using DP ?

my code got TLE 8, any help?

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

What is the test Case 13 for C. I was trying DP. Btw I found E to be easier than B and C.

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

    The height of the rightmost pillar must be 1.

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

      :(. I have to improve my problem reading capability, I took eternity only to understand the problem.

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

    "Note that you must start and finish the pipeline on height 1 and, also, it's guaranteed that the first and last characters of the input string are equal to 0."

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

    You could just brute force for B. Check out every possible square, in O(N^2) time. N < 50.

    For C, DP isn't actually necessary, although it took me a lot of time implementing.

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

    can't we solve it using greedy? I tried it using greedy but got WA on test 13 and still don't know why.

    idea — first find all the continuous segments of zeroes with length > 1 and for each of them check the min of both possibilities and then just calculate the answer.

    entertained the first and last element case by combining them (they become a segment of 2 or greater elements).

    Edit: it should start and end at 1 (i didn't entertain it)

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

It took an hour for me to implement C and by the time I realized contest was already finished :P

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

Is authors' solution on problem F has time complexity $$$\mathcal{O}(n \sqrt{n})$$$? If yes, why is limits on $$$n$$$ is so big?

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

Did someone submit HLD + SQRT decomposition (fact that there SQRT groups of queries grouped by length of string) solution in G?

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

How to solve problem D?

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

    +1

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

    Use including exclusion, I calculate the number of ways to sort each part and minus the number of ways to sort both parts. The answer initially is n!.

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

      Can you explain how to calculate the number of ways to sort the arrays? I thought the same thing but i wasn't able to implement it.

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

      Could you explain the intuitive idea to compute the number of ways to sort both parts. Just want a hint ,i dont want the complete solution.Thanks in advance.

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

        Sort the list of tuples (sorting by first element, then second by default). Then check if the list is sorted by second elements. Ignoring duplicates, there will only be one (if any) valid sorting, so you need to count how to add in the duplicates.

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

Probably, the most "un-educational" educational round I've ever seen.

It's not a bad problemset, but I expect more DS and algorithm in an ed round.

In addition, the only Data Structure task in the contest (G) is actually similar to Chinese NOI 2011阿狸的打字机. (Link to problem)

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

Can you tell me please how to solve E?

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

    Let's say desired number is $$$X$$$. If you could query only one number, you would send 0 and get $$$X$$$ XOR 0 = $$$X$$$ as an answer. If you sent some degree of 2, you would get $$$X$$$ XOR $$$2^k$$$ = "$$$X$$$ with its k-th bit reversed". Generally, if you send an arbitrary number, you would get $$$X$$$ with some of its bits (the ones that are set to 1 in your number) reversed. The only problem is that you do not know which bits are reversed when you send 100 numbers.

    My idea was the following: use only odd bits in the first query and only even bits in the second query. So, the first query will contain 100 numbers with some of their odd bits set to 1, and the second query will contain 100 numbers with some of their even bits set to 1. Then you will get the following as answer:

       X = 100010110
    ANS1 = 101000111 // 1st, 5th and 7th bits were reversed; XOR happened with 1010001
    ANS2 = 100011100 // 2nd and 4th bits were reversed; XOR happened with 1010
    

    When you compare ANS1 and ANS2, you will see that they differ only in those places where bit reversal happened:

    ANS1 = 101000111 // 1st, 5th and 7th bits were reversed
    ANS2 = 100011100 // 2nd and 4th bits were reversed
             ^ ^^ ^^
    

    That means that ANS1 XOR ANS2 (1011011) will give you the set of bits that were XOR-ed in both queries. Then you just need to check which two numbers among those 200 you sent form the same set of bits. In other words, find $$$x_i$$$ from 1st query and $$$y_i$$$ from 2nd query such as $$$x_i$$$ XOR $$$y_i$$$ = ANS1 XOR ANS2. Then you can find X as ANS1 XOR $$$x_i$$$ or ANS2 XOR $$$y_i$$$.

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

    Let the input results be N and M and the answer be A. Then, we have two equations: A ^ X = N and A ^ Y = M, where X is in the first output set and Y is in the second output set. Taking the XOR-sum of these two equations gives A ^ X ^ A ^ Y = X ^ Y = N ^ M.

    Then, if we can find two sets of 100 numbers such that there are no two distinct pairs of integers, one in the first set and the other in the second set, with the same XOR, we're essentially done: find N ^ M, and then use that to find the unique X ^ Y such that X ^ Y = N ^ M.

    This is fairly easy--just take 100 integers that make use only of the first seven binary digits as the first set and 100 integers that only use the next seven binary digits as the second set. One simple construction is to use 1 through 100 as the first set and 1 * 128, 2 * 128, ..., 100 * 128 as the second set. From here, we can iterate over all pairs of these integers to find the appropriate X and Y. Afterwards, reconstructing the answer is easy--if A ^ X = N, then A = X ^ N, so once we know X we can simply print X ^ N.

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

      Thank you too!

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

      We can also try to bruteforce for these two sets(although it is not guaranteed we will find them this way).

      I assumed that numbers from the first set are $$$0, 1, ..., 99$$$ and was greedily choosing $$$b_i$$$ as the least number, such that its xor with every $$$a_j$$$ doesn't equal to any of past pairwise xors. The biggest number in the second set happened to be $$$12672$$$.

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

      Cool, this looks simpler than I imagined to myself :)

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

      We can even simplify that logic:

      If we took "100 integers that make use only of the first seven binary digits as the first set" then, after getting the answer, we will know the next 7 bits of X, since all integers in the first set have same 7 most significant digits.

      Analogically, asking the second set will lead us to knowing 7 least significant bits. Profit.

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

In problem A, this solution print the answers in one line, while it is required to print them in seperate lines. Still, it received an AC verdit.

Should this solution be considered AC or WA?

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

The distribution of the number of accepted submissions of each problem is like Div. 3!

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

If you liked problem F, here’s a similar one for you. https://open.kattis.com/problems/modulodatastructures

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

would someone explain why this submission got WA on test 4 , please :)

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

    Change every int to long long int (you can leave int i), and you will get AC.

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

for problem D I tried taking all possible ways to get the first half sorted basically taken the frequency of every number and multiplying those , and the same for the other half , now if the sorted state of the array is sorting the first half along side the other half (both half's are sorted ) then the answer is all the possible permutations — max( number of ways the first half could be sorted , number of ways the other half could be sorted ) otherwise its gonna be all the possible permutations — (number of ways for the first half + number of ways for the second half ) note that there is only one way for the array to be sorted( bad ) but we must calculate the number of times this happens consider the example 1 1 2 2 3 3 the only way it could be sorted is 1 1 2 2 3 3 but this could happen 8 times factorial( frequency(1) ) * fact( freq(2) ) * fact( freq(3) ); = fact(2)*fact(2)*fact(2) = 2*2*2 = 8 can someone prove this wrong please

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

I don't know why my D wrong answer on pretest 13... who tell why? thank you very much 59302847

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

Is there any hack for a greedy solution for problem C ?
Because, I see ppl talking about DP solutions, while I felt greedy should work. :)

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

    Greedy seems correct to me. Basically, you only need to take care of separate segments that look like ...100001..., and you either select to cover it all at height 2, or choose to dive at least once to the height 1. But if you go to height 1, you already spend 2*a, and there is no reason to put any additional pillars on this segment. It is just that DP is a safe bet :)

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

      Yeah, dp solution is just quick to arrive as soon as you know you can fit the statespace in memory and pass the time limit. And can promise correct answer.
      Where as greedy took time to prove and is still risky.

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

    My solution greedy: https://codeforces.com/contest/1207/submission/59310430 DP code faster than greedy. I think so..

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

I think the problem D statement was not clear ... there is no thing refer the the permutation is of indexes not permutation of elements it self ( it different in handle the same permutations )

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

Help me with Problem B please.

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

      Got it. Thanks that helped. If you don't mind, Can you explain me Greedy approach for Problem C.

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

        for every index we check the position of the next 1 we iterate through the array and check if we should go up or go down and then calculate the cost we start at state down 0 and move up only if a[i] = 0 && a[i+1] = 1 this must happen always now if a[i] = a[i+1] you shouldn't change the state just calculate the cost and if a[i] = 1 && a[i+1] = 0 calculate the value i would lose if we go up , and if we go down and go according to the min

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

What is the hacking case for problem B ?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +14 Проголосовать: не нравится
    hacking test for my submission
    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      It should be -1 isn't? My solution does so.

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

      so if we pick x=3,y=3, the 2x2 matrix will only change the value of A(x,y)?, i thought we cant do that :(

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

        You can't pick (3, 3) according to the statement.

        ... In other words, you choose two integers x and y such that 1≤x<n and 1≤y<m, and then set Bx,y, Bx,y+1, Bx+1,y and Bx+1,y+1 to 1.

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

        No we can't do that. As problem statement says "you choose any submatrix of B having size 2×2". When you take x=3, y=3 then the 2x2 matrix will not be a submatrix of B.

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

is their is something better it cost me 7 wa 5 what is that test that fails my solution i tried all possible cases thanks in advance.my submission

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

    Try this snippet:

    5 50
    0 0 0 1 1 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 1 1 0 0
    0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 1 1 1 0 0
    0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0
    0 0 0 0 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
    0 0 0 0 1 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 0
    

    The answer is not -1.

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

Can anyone explain me the logic of solution to question A?

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

in problem D,can someone explain me the sequence include one pair is non-descending or non-increasing ,thanks???

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

Nice contest!

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

    HOW? MAXSUM = MAX(yi)*q <= 1000*500000 < 1000000000 (it must be int) Your solution get WA only because you should get sum of all numbers from 1 to 500000 which have remainder y, but you sum all numbers from 1 to q which have remainder y

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

    2000 revisions wut

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

    For those who are curious. Comment You can't hide it by 2000 revisions.

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

Can G be solved without Aho corasick and segment tree ? Like using hashing and sqrt decomposotion ?

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

    You can use modified suffix array algorithm to build something like suffix array on the given strings.

    The modification you need in the suffix array is that on the $$$i$$$-th iteration you should compute the equivalence class for every vertex $$$v$$$ of the ``string tree'' (the class of the suffix of the $$$v$$$-th string from the input which has length $$$2^i$$$).

    UPD: Forgot to mention that you should consider reversed strings in this approach to build suffix array correctly.

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

      Even if we build the modified suffix array, how are we calculating the answer for each query ? I have a solution but that is quite ugly.

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

        With suffix array we can find all occurences of the string $$$t$$$ from the query in our strings in $$$O(|t| \log n)$$$. To do so, you may do two binary searches.

        Then you have to consider only the vertices that belong to the path from the root to the vertex we need. The easiest option that comes to my mind is to do DFS on the string tree and use Fenwick tree to maintain the vertices we need, but maybe there's something simpler.

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

    Hey I solved it only with Aho corasick, Can you explain your approach with segment tree? Mine is solved ofline and having an array of frequencies for each string (like all the matches from the root to current node). So basically I do a dfs traversing the tree and process the current character of the current node, and then answer all queries. In order to update the array, I iterate over the fail links in the aho corasick. The code is very simple if you know Aho corasick. It works in N*sqrt(n). code

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

      Can jumping through the failure link again and again timeout ? What happens if the query string is all aaa...aaa and so is the given string ?

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

        The trick here is that there are only sqrt(n) different lenghts. So you cannot jump more than sqrt(n) for each node in the aho corasick (notice that actually I'm not using the direct fail link but the output fail link.

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

          ** notice that actually I'm not using the direct fail link but the output fail link. ** Now I get it. I didn't have this observation. My solution is almost the same. Instead of jumping through the failure link, I use a data structure that can add a value to some node and query the sum in a subtree. This can be done using euler tour of the tree and segment tree.

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

    I solved it with centroid decomposition.

    We only need two string algorithms. Denote $$$n = |STR|, m = |PAT|$$$:

    1. O(n log n) preprocessing, O(m log n) counting of appearances of pattern in string
    2. O(n) counting of appearances of pattern in string

    I did the first by binary searching suffix array, and the second is just KMP.

    Given these two, we can solve the problem with centroid decomposition. First read all queries and place them into the nodes in the tree where they occur. Find the centroid of the entire tree. Preprocess the string from the root to the centroid. Then DFS all queries in the subtree of the centroid, and add to their answer the number of the pattern's occurences in the preprocessed string (with algorithm 1), and its occurences overlapping with the end of the string but not contained in it (with algorithm 2). Note that we only have to process a string with length 2m in algorithm 2.

    After processing the centroid, clip its subtree away from the original tree and recursively solve its subtrees. Repeat until the original tree is empty.

    This correctly answers the queries by dividing the query string into multiple strings $$$S = S_{1} S_{2} \dots S_{k}$$$, and calculating its appearances inside each individual $$$S_{1}, \dots, S_{k}$$$ (with algorithm 1) plus its appearances not inside any individual $$$S_{i}$$$ with algorithm 2.

    Total time complexity is $$$O((n + m) \log^{2} n)$$$ where $$$m$$$ is the total length of the query strings, since due to the centroid decomposition we do the preprocessing of algorithm 1 on every character at most $$$\log n$$$ times, and we do the matchings with algorithms 1 and 2 for every pattern at most $$$\log n$$$ times. Note that if a suffix automaton was used instead of binary searching a suffix array, we could do algorithm 1 in $$$O(n)$$$ and $$$O(m)$$$ time, bringing the whole algorithm to $$$O((n + m) \log n)$$$.

    Code: 59351316. My submission during the contest TLE'd due to doing $$$O(n \log^{2} n)$$$ suffix array construction.

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

The penalty of taking long long is too high in F, anyone agree with me?

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

    Can't agree with that.

    Model solution with ints replaced by long longs works in something like 2.2s.

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

      Mine works in 3.993 :( Any ideas for improvement?

      Link

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

        Okay, it seems I was wrong.

        I replaced only the variables required to store the answers and the result on each query with long longs. It seems that creating a new long long in each for-loop and changing it can be really heavy.

        I am sorry for putting the constraints too high.

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

        One if statement can be taken outside the loop, down 0.1 sec only though. https://codeforces.com/contest/1207/submission/59323107

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

        You should probably know, that the modulo operation is much heavy than simple addition, so decreasing the number of taking modulo is almost always good.

        In this task you can decrease number of modulo operations by decreasing the "sqrt-constant". For example, changing $$$700 \to 400$$$ leads to two times speedup, so the solution with int64t works in only $$$2$$$ seconds.

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

    My solution with long long works in 2s (59309544)

    However, just because of the adrenaline of the contest, I couldn't notice that long long wasn't needed.

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

So sad. I thought minimize answer for problem B. too hurry :(( i spent 30 minutes for it

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

How to solve F?

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

    For large x, you can easily accumulate all values in a (There are about 500.000 / x indices with remainder y).

    For small x, this is not suitable. But for a small x, you can maintain a 2D-Table (i,j) := Sum of all values in array slots with index % j == i. Updating this table for a single query takes j steps.

    Now use the sweet spot K = sqrt(n) to decide if x is small (about 700 for n = 500.000, but depending on the constant factors of both sides this value can be shifted 'slightly' between at least 400 and 1000.)

    Update: - the array in O(1) - the 2D-Table in O(sqrt(n)) is about 700 Query: - Large x (x > K = 700) in O(n / x) is about 500.000 / 700 =~ 700 - Small x : query the table in O(1)

    For n queries you get a total of O(n sqrt(n)).

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

I can't understand why overflow (task C) 59307028 (may be I am wrong and it is not overflow)

There is no hard limits

Third Edu round in a row when I change algo to BigInt (previous five minutes after contest)

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

I still do not understand the implementations of D. The solution is, (more or less obvious)

allPermutations - permutationsSortedByA - permutationsSortedByB + permutationsSortedByAandB

So far, so simple. The numbers are calculated using factorials. But, how do we get the number of permutations sorted by a and b? I dont get the idea, even after reading the working codes.

Somebody explain this?

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

    deleted (I am not right)

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

    allPermutations = n!

    permutationsSortedByA = multiplication of count of first value in pair

    permutationsSortedByB = multiplication of count of second value in pair

    permutationsSortedByAandB = multiplication of count of each unique pair

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

      What about like folowing 4 pairs:

      2 1
      3 2
      3 3
      4 4
      

      There are two perms sorted by a, one by b, and one by both. How do I find the number of both if there are no duplicate pairs?

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

        Check if sorting by first, second will also get sorted then it will be 1 else it will be 0.

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

    Sort the array by first number, ties broken by second number. Then check if a[i].fi <= a[i+1].fi & a[i].se <= a[i+1].se. If so, then count occurence of each pair and arrange then in fact(cnt) ways.

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

    My idea that sortedByA : if all A is equal than answer n! because each permutation is sortedByA, now multiplicate factorials of number of equal numbers by A: 1,1,1,2,2,3,3,3,3 -> 3!*2!*4! Now numbers of permutations SortedByA, SortedByB, SortedByAandB can calculated in same way. (1,1),(1,2),(1,3),(2,2),(2,2),(2,2),(2,3): A(3!*4!), B(1!*4!*2!), A_B(1!*1!*1!*3!*1!)

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

      What happens when there are no permutations that are sorted by A and B?

      The first test case is an example of this:

      3
      1 1
      2 2
      3 1
      

      According to your idea:

      SortedByA = 1! * 1! * 1! = 1

      SortedByB = 1! * 2! = 2

      SortedByAandB = 1! * 1! * 1! = 1

      And the result is 6 - 1 - 2 + 1 = 4

      But the actual result should be 3.

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

Any explanation on why the following solution for E does not work would be appreciated.

Make a query with the integer set S = {1, 2, 3..., 99}. Let the result obtained from the judge be result_S. Similarly, make a query with the integer set T = {100, 101, 102..., 199}. Let the corresponding result be result_T. Now, result_S = x XOR i, where i belongs to S. Also, result_T = x XOR j, where j belongs to T. Taking an XOR of result_S and result_T yields i XOR j. Brute forcing over all possible values of x and i should be sufficient to determine x_actual, I think.

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

    You should choose 2 possible sets of 100 numbers such that there is unique pair (i,j) which gives that i xor j value to guarantee that your answer is correct.In your case (i,j) may not be unique(For example in your sets consider two cases, case1:i=3 j=127 and case2: i=2 j=126, both give same xor value which is 124).

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

      Wouldn't i XOR x and j XOR x be sufficient checks?

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

        They would be sufficient checks if you choose sets S and T such that xor of numbers in every pair (i,j) where i is in S and j is T is unique. Otherwise there would be a possibility that two different numbers satisfy the conditions as stated by you. So if we choose S={1,2,3,...,100} and T={1*128,2*128,....,100*128} it would be guaranteed that for every (i,j) i xor j gives a unique number(since last 7 bits of every number in T is 0 and first 7 bits of every number in S is 0).Then you can solve the problem as you have stated.

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

    first of all, your first query has 99 numbers, not 100. But the i^j of your sets are not unique, for example 97 ^ 101 == 98^102.

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

Editorial please.

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

Problem F is just the reverse version of this problem:

https://open.kattis.com/problems/modulodatastructures

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

How to solve problem G?

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

I feel sorrow at missing this contest. Problem A really convinced me.It 's interesing. My solution: 59330841

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

Won't there be any system testing (on hacks), because it's showing final standings?

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

Ever pondering of entertainment-al rounds in addition to education-al rounds? Let's watch our newest entertainment-al content: https://youtu.be/D3wC1hgWcZA. Feel free to like, share, subscribe, upvote and feedback. Thanks a lot.

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

Is it rated?

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

Is it rated? Why I have no change in rating?qwq

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

How to solve C by dp?

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

Is Problem G solvable with Suffix Automaton ?

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

After I saw the announcement, I added if(n==1)cout<<1<<endl; to my code.

I have perfectly reached top stupidity.

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

Can someone help me with 59286702. I have got wrong answer on case #87. while I am getting correct answer on my local machine. Any help will be appreciated. I think there is some issue with 14th line int a[n][m]={0}; I checked custom invocation with G++11, it works fine. In G++14 it gives wrong answer. Please help.

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

    The problem comes from this line:

    int a[n][m] = {0};

    I'm not sure how it works, but it just wouldn't initialize all elements to 0 properly.

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

      Yeah, will search for it. Thanks a lot.

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

        When did you edit your comment though

        I just made it look like a weird conversation xD

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

      yes you're correct.Though it works perfectly fine when done on single dimensional array.Still memset is a bit safer choice.

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

Очень хороший кантест от души спасибо

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

Will it show the rank list of hackers?

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

Can you add top hackers awoo

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

    Sorry, I found out it'd been broken after the previous round and haven't fixed it yet.

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

Is there is any better way to solve F other than obvious q sqrt(n)

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

Does not educational round show top hackers anymore?

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

Editorials please

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

When will be the tutorial?

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

Когда будет разбор?

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

Wanted help with problem C dp solution. I have the following: MY DIV2-C Solution. I added 1) comment line in the code by a hunch... and it gives AC with it... What I dont understand is how this line works and gives AC? Thanks for the help in advance.

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

f**k you ,you son of b*ch ,can not giving good statement please do not give contest