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

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

Привет, Codeforces!

Я рад пригласить всех на раунд #489 Codeforces, который состоится уже завтра, в понедельник, 18 июня 2018 г. в 19:35. Раунд будет рейтинговым для всех участников из второго дивизиона (то есть для участников с рейтингом меньше, чем 2100). Как обычно, мы будем очень рады видеть всех участников из первого дивизиона на нашем контесте вне конкурса!

Задачи на этот раунд придумывали и готовили мы, ученики московской школы №2007, Дмитрий gop2024 Григорьев и Фёдор ---------- Ушаков. Большое спасибо Андрею GreenGrape Райскому за помощь в подготовке задач и тестировании раунда, Ильдару 300iq Гайнуллину и Амиррезе Arpa Пурахавану за помощь в тестировании раунда, а также координатору Николаю KAN Калинину за то, что наши зачастую странные и непродуманные идеи превратились в раунд Codeforces и, конечно, Михаилу MikeMirzayanov Мирзаянову за потрясающие платформы Codeforces и Polygon.

Вам будет предложено 5 задач и 2 часа на их решение. На протяжении раунда вы будете помогать необычной девочке Насте, которая живет в Байтландии и которой на день рождения дарят очень странные подарки :). Разбалловка раунда будет традиционно объявлена ближе к раунду.

Для нас обоих это первый и, надеюсь, не последний раунд на Codeforces, и я надеюсь, что вам понравятся наши задачи. Прочитайте условия всех задач. В любом случае, всем удачи и высокого рейтинга!

Ждём завтра на контесте!

UPD Разбалловка раунда стандартная — 500-1000-1500-2000-2500

UPD2 Спасибо всем за участие в раунде! Я очень надеюсь, что наши задачи вам понравились; если нет, то я постараюсь порадовать вас на следующем своем контесте :).

Список победителей контеста:

Div.2

  1. sminem

  2. NguoiHocTinLoai2

  3. YaKon4ick

  4. HanaElhami

  5. pajenegod

Div.1 + Div.2

  1. dotorya

  2. Benq

  3. anta

  4. sminem

  5. kevinsogo

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

UPD3

Разбор тут

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

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

Is it rated? don't downvote plz, tomorrow is my birthday

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

Finally someone remembered to thank both KAN and MikeMirzayanov.Hoping it would be a good round after the last one.Good Luck everyone.

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

score distribution ?

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

Хммм, у моей знакомой Насти сегодня день рождения, пойду спрошу, что ей подарили ;-)

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

Usually strange gifts will transferred to someone else later. I predict that we will become this "someone else". However, in addition, Nastya will tell us what to do with our gift.

Nastya forces us to do strange things. Do not be like Nastya.

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

I was hoping to see one thematic contest of the world cup

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

Раунд будет рейтинговым для всех участников из второго дивизиона. Как обычно, мы будем очень рады видеть всех участников из первого дивизиона на нашем контесте вне конкурса!

Теперь ведь раунды второго дивизиона являются рейтинговыми и для участников первого дивизиона с рейтингом до 2100 – http://codeforces.com/blog/entry/59228. Нужно поправить текст.

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

    Просто теперь все считают что первый див начинается с рейтинга 2100))

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

      Я так не считаю :) – в Div1 + Div2 раунде дивизионы делятся по рейтингу 1900.

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

hoping to see more of mathematics ,all time favorite GreenGrape

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

Getting 502 Gateway error, hope that will be fine at contest time :)

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

Expecting a good contest....

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

Score distribution?

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

Too keked

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

In the problem C : Also, you should find the answer modulo 10^9+7 Can someone explain what this means,please?

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

    You should ask questions on "problems" page. There you can get answer momentarily.

    If the answer is A, you should print the remainder of division of A on 109 + 7.

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

Hi, in problem C im having WA on test number 2. However on my computer (with the same code) it gives the correct answer. Can someone check this out please?EDIT:It was my bad, sorry.

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

Wtf, math contest.

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

Mathforces Round #489 (Div. 2)

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

What is unexpected verdict when trying to hack problem C?

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

Drunken and sleepy ㅜ_ㅜ

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

How to solve div-2 B?

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

    There are two numbers. Obviously, since gcd is x, therefore common factor is x. so now both have factor x. So first number is in form a*x and second is in b*x and gcd(a, b) must be equal to 1. Since both number can't have other than x. Now GCD* LCM = first_number * second number. So x*y = (x*a) * (b*x) So y/x = a*b so we need to find all pairs (a, b) where gcd(a, b) ==1 && min(a*x, b*x)>=l && max(a*x, b*x)<=r and damn this count is the answer. There is just one catch, that y must be divisible by x. Otherwise the answer will be 0.

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

How to solve Div 2 B ?

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

    If y is not divisible by x, answer is 0. Otherwise, all pair (a, b) that satisfy the condition can be represented by (x * a', x * b'). Let , , . Now the problem is counting number of pair (a', b') in range [l', r'] such that GCD(a', b') = 1 and LCM(a', b') = y'.

    This can be done by iterate over all divisor d of y' and check if pair satisfy all the condition above.

    My implementation

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

      I think its can be done just by iterate over all divisor d of y

      and check if each pair count number of pair satisfy all the condition:
      
      l<=a<=r and l<=b<=r and gcd(a,b) = x and lcm(a,b) = y
      

      its can be done inO(d^2) where d is number of divisor of y...

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

    There are two numbers. Obviously, since gcd is x, therefore common factor is x. so now both have factor x. So first number is in form a*x and second is in b*y and gcd(a, b) must be equal to 1. Since both number can't have other than x. Now GCD* LCM = first_number * second number. So x*y = (x*a) * (b*x) So y/x = a*b so we need to find all pairs (a, b) where gcd(a, b) ==1 && min(a*x, b*x)>=l && max(a*x, b*x)<=r and damn this count is the answer. There is just one catch, that y must be divisible by x. Otherwise the answer will be 0.

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

      why min(a*x, b*x) >= l and not a*x >= l && b*x >= l ??

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

        You have to check both a*x>=l && a*x<=r && b*x<=r && b*x>=l. I done it in two statements min(a*x, b*x) >=l Since if minimum is greater than l, then the number which is greater than or equal to other number will always be greater than l. Same goes for max(a*x, b*x)<=r Since max of both number is less than r So the other number (which is less then the first one) will always be less than r. You can always check all four statements if you like. a*x>=l && a*x<=r && b*x<=r && b*x>=l.

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

          Yeah. Sorry that was a stupid question! By the way, can you explain the case for 0. why would it be 0?

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

            First of all question was not stupid. It was cool. Your solution got a problem. I, myself got 2 WA on this one. Secondly as i told you two numbers are in form a*x, and b*x Now lcm * gcd = product of number (for 2 numbers) so y*x= a*x * b*x so y=a*b*x so y must be divisible by x. if not divisible you can never find any a, b irrespective of l and r. So the count is 0 in such case.

  • »
    »
    6 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится +6 Проголосовать: не нравится
    1. Find the prime factors of y/x
    2. For those prime factors which are present more than once, replace them with their product. For example: 12 = 2*2*2*3*5*5 should be made 12 = 3*8*125. Store these in a vector, say, "facts".
    3. It can be noted that size of vector "facts" is not more 15. So we can iterate on all subsets of facts to multiply each value of facts to either a or b. (a and b are numbers to be found). This can be done using bitmasks. For calculated values of a and b, check if they are between l and r, and increment the ans variable.
    4. Check specially for case when y is not divisible by x, and the case when a=b. Here is my solution 39374707
  • »
    »
    6 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Simple Explanation is as follows:
    LCM(a, b) = a * b / GCD(a,b) ....... eq(1)
    and if g = GCD(a, b) you can write a = p * g ; b = q * g such that p & q are coprime i.e. GCD(p, q) = 1
    So above equation 1 can be rewritten as
    LCM(a, b) = ((p * g)*(q * g))/g
    LCM(a, b) = p * q * g ; where g is gcd(a,b)
    So now problem became: for given integers y and r , count number of unordered pair (p,q) such that y = p * q * r and p & q are coprime i.e gcd(p, q) = 1.
    That you can do in O(sqrt(N))
    Ref Solution

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

How to solve D?

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

    I thought of Divide & Conquer based solution but couldn't merge efficiently.

    If somebody solved like this, then please help how!

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

    Notice that the product will get big really fast. So for each starting index you can just iterate over the end index until the product gets too big (e.g.  > 2·1018). This will have runtime .

    The only problem with this approach is that this doesn't hold if there are a lot of 1s in it. But you can modify the approach from above so that you jump over the 1s, and check in O(1) if there is a solution (there can be only one) with the 1s that you jumped over..

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

    Couldn't code it in the time I had, but my idea was something like this:

    I stored the sum upto n numbers in an array, and the value of k for the first n numbers taken consecutively in another array k[n]. Now, for every element for which k[i]>=k(required), just check if there are consecutive numbers up back till the last element with this property.

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

    I've compressed segments, that contains only "1". Then you can just bruteforce all segments ([0; 0], [0; 1], ... [0; n-1], [1; 1], [1; 2], ...), refreshing p and s for O(1) and breaking when p>z, where z=(2*10^5)*(10^8)*(10^5).

    It's working for O(n*log(z)), but you must handle overwflows carefuly.

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

my incorrect (WA on pretest 7) solution for B — Nastya Studies Informatics is to find all factors of y, then generate all pair, if the pair satisfy gcd(first, second) == x && lcm(first, second) == y then increment result

what is wrong with the solution?

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

    You should check the case 1 1 1 1

    It cost me 3 WAs as well :(

    Edit: Answer for this case is 1 BTW, it gave me 2 due to an error in my code only for this specific case.

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

    You wrote in the program:

    int lcm(int a, int b)
    {
        return (a*b)/gcd(a, b);
    }
    

    If a and b are too big, it can be overflow (109·109 = 1018 >  maximum value of int).

    For example:

    • test case: 1000000000 1000000000 1000000000 1000000000

    • correct answer: 1

    • your output: 0

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

worst contest with no creativity

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

Was E square root decomposition?

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

    I tried a sqrt approach, it was TLE 13. I was using unordered_maps, so I tried to implement hashes, but didn't finished in time. I think there is a log solution

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

      It's too slow solution, the same our solution worked >10 sec

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

      Usually if you think it is solvable with sqrt-decomposition, dump the idea and look for a better solution. In most the cases you would be right.

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

    Of course, No :)

    Idea is simple, there are not many positions that greater than sum of previous.

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

      can you explain more ?

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

        It likes fibonacci sequence, there are little terms  ≤ 109. So what you need to do is just pick the maximum until it less than or equals 0.

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

          The way I thought about the problem was to always start searching at the first index i = 0, and if that index wasn't the shaman-king then go to the smallest index j such that j > i and aj  ≥  sum(A[: i + 1]). Continue doing this until there is no such index j. All of this can be done quickly using segment trees. Worst case aj should double in size (not Fibonacci) for each iteration, and all of the segment tree operations will run in time so my solution should run in . 39387502.

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

          chemthan Could you please explain this in brief?

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

            Assuming i1 < i2 < ... < ik are all positions d such that ad > a1 + a2 + ... + ad - 1. Then obviously aic ≥ ai1 + ai2 + ... + aic - 1 + 1. We have: ai1 ≥ 0, ai2 ≥ 1, ai3 ≥ 2, ai4 ≥ 4, .... Because ai ≤ 109 so the number of terms k is not big.

            Then let fd = ad - ad - 1 - ad - 2... - a1, using a segment tree to get all d s.t. fd ≥ 0. The number of d s.t. fd > 0 is less than log2(109) so each query we get out at most that number until fd ≤ 0.

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

    Hey My square root decomposition solution 39389380 passed after contest. (missed submitting during contest by 1 minute). Have a look.

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

Guys look at last two places :o

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

    You were trying to reach new record on Codeforses or you just like the number 228? (Or it's the result of competition between two brothers?).

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

pretest #12 of C? any idea?

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

PS: Found mistake . It doesnt work, Sorry

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

It was very nice contest:::::: thanks

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

pretest #12 of C? any hints please verdict- WA

Edit this is the code please tell me whats wrong-http://p.ip.fi/_4l8

Update- I got it thanks for looking over my code everyone. In python n//2 and int(n/2) are not the same it looks like.

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

when will the rating changes happen ? (sorry for bad english)

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

I don't like math problems.

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

I read only A, B and C, but looked more a math contest than a programming contest to me! Thanks to the author, anyways.

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

Managed to solve A,B,C. How to solve D?

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

    I think the main idea is that the maximum possible product is TOTALSUM*k, so there can be at most log_2(TOTALSUM*k) elements larger than 1 in a valid array.

    Hence we can bruteforce over all possible (i,j) where i is the position of the first element larger than 1 in the array and j is the last position.

    Once you have that you just need to look at how many extra ones you can add to the left of i and to the right of j.

    I did this but I made a mistake I guess.

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

What was Test case 4 for C?

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

How was in Problem C 'n==1' solved??

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

    Just as n==2,n==3,n==4 and so on.

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

    because at the end there will be twice the dresses, but there can be one less dress with 50% probability, so at the end there will be 2 * x and 2x + 1 dresses each with 50% prob. Rest is simple.

    This gives f0 = x

    answer is twice of fn

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

It sucks when you spend all your time thinking about the solution, and then find out later that the solution(s) are googlable :/

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

I have a doubt. Suppose I submit a solution which passes all pretest. Then I submit a solution which fails on pretest. Will then only my 1st solution be considered ? Or i will have some penalties?

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

My idea for D:

at most I will multiply with 62 numbers greater than 1, so for every number I store the next number greater than 1, and I should take care of the ones between, am I missing something???

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

RIP ratings.

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

This round makes me realize how poor my math is.TAT.

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

This round makes me realize how poor my math is.TAT.

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

In problem A i was having time limit exceeded on pretest 6 as the judgement. Did any one face the same problem and knows how to fix that?

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

    your code link ??

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

        It's kinda obvious your solution works in O(n^2) for n = 1e5. No surprise you got TL.

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

          can you explain more why that obvious?

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

            _

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

              1) He said he got TL6, not WA1. He just post the wrong link. 2) It's obvious that is was some debug output and he undestands he shouldn't use printf instead of scanf. 3) Now he posted correct link.

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

            Suppose there is no a[i] = 0; Then your code is simmilar to:

            for (int i = 0; i < n-1; i++)
               for (int j = i + 1; j < n; j++)
               {
                   do_something();
               }
            

            Still not obvious?

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

            There is a nested loop in your code:

            for(int i=0;i<n;i++){
              ...;
              for(int j=i+1;j<n;j++){
                ...;
              }
            }
            

            This nested loop takes O(n2) time.

            Note: For this problem, I recommend you to use set data structure.

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

            Your code complexity if N*N (as your code runs n times for every outer loop.) So n*n statements minimum. Generally 1 sec = 10^8 operations. and here n=10^5 so n*n = 10^10 so it will take 100 secs. That's why you are getting TLE. Hope it helps.

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

Спасибо Димону за раунд. Задачи очень жосские. Возьмите мое пятое питание, только бы он делал еще раунды.

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

div2B was not made for div2B.

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

Problem E was really nice.

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

How to solve DIV2 C?

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

    Observe that after k months, there can be 2k * x, 2k * x - 1, ... , 2k * x - (2k - 1) clothes in the wardrobe, with equal probability .

    By using definition of expected value, we find that the expected number of clothes after k months is . The answer to this problem is twice of this number, i.e. 2k(2x - 1) + 1.

    Note the special case: if x = 0, the answer is 0 no matter what k is.

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

    Let f(x, k) be the answer for input x and k.
    Then we have the recurrence,
    For k ≥ 1,

    and f(x, 0) = 2x.

    By induction, you get f(x, k) = 2k + 1x - 2k + 1.
    Use repeated squaring to evaluate the powers with the right modulus.

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

Can D be solved using two pointer both starting from beginning ?

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

Forgot to take mod in C fml. Also can someone tell whats wrong with my code for D — http://codeforces.com/contest/992/submission/39387013 ?

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

B is a bit too hard, and the problem involved a lot of maths, but the problemset is nice overall. I liked B and D the most.

Also, I appreciate the fact that pretests is strong and included corner cases (n = 0 in C).

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

    Problem E smells like an interesting problem as well. It's the kind of problem you think you'd go like 'aaa, hmm, mkay, that's pretty cool' haha

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

      I didn't come up with that observation (I thought the upper bound is at first, so RIP). But now knowing that, I think E is also a cool problem.

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

For problem E, can we solve sqrt(q) queries at a time by pre processing for each sqrt block. My idea is to find all the indices that are updated in that block and then we make a new array having all the subsequent indices that are not updated together as a same element. We can maintain the sum of that element and also create a map to check the sum requirement of all the indices in that element, while for indices that are updated, we can check if the prefix sum till that element is equal to that element. Time Complexity will be O(n * root(q) + q * root(n)).

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

What was test case 5 for c?

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

Solution of problem B already exists on the internet. link : Click . Found it after the contest!

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

    How to modify it to include the range specification?

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

      Edit:

      Nevermind, like a tilted fool I read the wrong block of code and didn't realize it wouldn't run in time, give me a minute

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

        That solution would give TLE because it iterates all the numbers until 1e9

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

      If you read the efficient solution which was given in the link above, you can see that the answer is 2^number_of_distinct_prime_factors(lcm/gcd). You can do this: bruteforce through all pairs of numbers that can be formed using distinct prime factors of lcm/gcd such that their multiplication is equal to lcm/gcd, and add to answer if both of them are in range [l,r]. That was my solution (not the best one i think, but it passed).

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

    Its not same at all. You also have to check if a and b are between l and r, which requires a lot more work.

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

What is pretest 9 in D and why did it bend me over?

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

Thanks for strong pretest of Problem C. To me it was easier than Problem B.

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

Why is the system testing happening so slow?

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

pretest 5 in B? Coldnt pass it

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

Am I the only one who really loves math problems?) Thanks to authors, problems were really nice, though harder than ussual.

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

The math skills...

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

The amount of number theory and partial sums is strong with this one.

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

What could the test case 63 be for Div2 C?...I see many WA's on that test (including mine).

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

the writer of problem B is germa 66 fan

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

Is a lot of test case the reason of this very slow system testing ?

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

In problem D, what is the maximum p, such what p/s=k exists?

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

    well i know that you could just simulate the entire problem, like iterate for i, then for j with j > i and with some optimizations like, jump over sequences of 1 and when current p is much bigger than s + (n — j) because p rises much faster than s the situation is unrecoverable so you stop the second iteration because you are sure to have no solution with current i ans j' >= current j, Getting a nlogn complexity. Now for your question the answer is s * k

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

      1) s is not fixed. 2) If we say that s = n*max(a) and k=1e5, when p=2e18 can't exist, because all of the numbers would be 1e8, and that means 1e8^n=2e18, which is false.

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

    You can take

    108, 
    100300, 
    199700 × 1

    to get

    p = 1003·1010, s = 1003·105, k = 105.

    Not sure if that's the worst case, however.

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

    Intuition: k should be max (10^5). We would like to use a small number of numbers because otherwise, p is going to be extremely large. So we would use 2 numbers. We would like one number to have the maximum value. So the equation is (10^8*x)/(10^8+x)=k. X is slightly more than 10^5 -> maximum p is slightly more than 10^13.

    I didn't prove it but I think it's right and should be easy to actually prove.

    It could overflow even unsigned long long. I have checked that a*b < 10^y with log10(a) + log10(b) < y.

    Also, I've accidentally set the limit to 10^13 in my solution and it passed.

    UPD: yes, maybe such test is impossible to create so that's just an upper bound.

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

      I know that's no argument, but my solution passed with 10^11 as a limit :D

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

      I was for a minute scared, what product can be 2e18, because i used >= and not > :D

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

      Hello Qumeric In problem C : in this solution link i have used modInverse but in this solution link i haven't because i just had to divide the variable by 2 and my numerator is already %M.... Can you please tell me why my answer was accepted in the first case and not in the second? ( M = 1000000007)

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

        Let`s think answer is 500000004. Then before divide you should have 1000000008. But you use modulo calculations and you have 1 instead of 1000000008. If you use modulo inverse you get correct answer. But if you divide by 2 you get 0 (1/2 = 0).

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

Ребят у меня в D Ошибка исполнения на тесте 132.. кто знает почему?? Изменил константу inf с 3*10^18 на 10^18 и зашло.. как такое может быть..?

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

Dear author(s),

Thanks for including n = 0 in pretests (Problem C). Thanks for not making it hackforces and saving my rating...

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

for C, the correct formula is 2^(k+1)*x — (2^k — 1) ? [after applying proper modulo] If yes, then why is my submission giving wrong answer? 39389996

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

    Should be overflow somethere.

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

    Take modulo of X before multiplying with 2^(k+1)

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

      Hello darkhorse7 In problem C : in this solution link i have used modInverse but in this solution link i haven't because i just had to divide the variable by 2 and my numerator is already %M.... Can you please tell me why my answer was accepted in the first case and not in the second? ( M = 1000000007)

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

        please attach the solution link

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

          oh sorry! in this solution link i have used modInverse but in this solution link i haven't because i just had to divide the variable by 2 and my numerator is already %M.... Can you please tell me why my answer was accepted in the first case and not in the second? ( M = 1000000007)

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

            you have to print ans modulo 1000000007. so you can't simply divide by 2. read this Link

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

              But my numerator is already % M and dividing by 2 would further reduce it then why do i again need to do %M?Please tell....

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

    if(b == 0) return 1;

    if(b == 1) return a%mod; // ( not a )

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

Yeah, now that I'm yellow I want to say that my D is wrong ):

It fails for this testcase:

10 2 
1 1 1 1 10 3 1 1 1 1

I think the answer is 3, but my code prints 2... I don't know how did it pass system test while failing on that simple case.

I don't deserve this :'(

Anyways, it gave AC 20 seconds before the end of the competition, so that was pretty cool (?

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

How calculate lcm in Div2 B?

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

can anyone explain D ??

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

    p/s=k; p/s<=k; p<=s*k<=2e18, so there will be at most log_2(2e18) elements in subsegments not equal to 1.

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

I fst in D in the 132nd test. However,I run this test on my own computer,it gives the right answer immediately. It makes me fuzzy. Here is my code:code link Can anyone give me a explanation?

UPD: I resubmitted the same code in C++17 and C++11, both get AC. Only in C++14, I got TLE again.:(

UPD2: It is due to compiler's(C++14) optimization(level 2 and above). (My undefined behaviour first, it's my fault.)

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

    First of all, how can you run the test if the test is not fully available? :D

    More to the point,

    LL PP = tempPro*a[j];
    if(PP<0||PP%a[j]!=0||PP/a[j]!=tempPro)break;
    

    This is NOT the right way of testing for overflow. In the C++ standard, you can read that signed integer multiplication overflow causes undefined behavior, which means that you have no guarantee of what happens. It also means it might run well on your machine, but not run the same way on the judge.

    The proper way to test for overflow is something like this:

    //checks if a * b overflows long long
    inline bool overflows(LL a, LL b) {
      return a > (LLONG_MAX / b);
    }
    

    This avoids undefined behavior. Have a look at this submission 39391459. It's your code, but with proper overflow checking. It gets AC.

    P.S. I learned this the hard way. To understand how wild undefined behavior can be, I've had this assert (multiply two non-zero numbers and get a zero result) pass on some online judge:

    void f(long long b, long long c) {
        long long a = b * c;
        if(b && a / b != c) return;
        assert(b != 0 && c != 0 && a == 0);
    }
    
»
6 лет назад, # |
Rev. 2   Проголосовать: нравится +2 Проголосовать: не нравится

Suppose mod is prime.

We know that (1/a) % mod is equivalent to (1 * a ^ (mod — 2)).

So what is (1 / (a ^ m)) % mod ?

  1. 1 * (((a ^ (mod — 2)) ^ m)
  2. find z = (a ^ m) % mod. then answer is = 1 * (z ^ (mod — 2)).

Both approaches in Problem C resulted in AC. I just want to make sure if those are actually correct and if you want, you can also include the proofs.

Not good at math. Only surviving by using theories and luck at appropriate places. :|

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

    From the exponentialtion laws we know: (ab)c = ab·c = ac·b = (ac)b Therefore:

    So both approaches are fine.

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

Got an idea for E 1:58 into the competition... Damn :D I understand the normal solution, but can someone who solved this with the sqrt decomposition elaborate? I didn't understand the comment that was posted here about it :)

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

    Most sqrt-decomposition solutions gets tle :D Idea is to make sqrt(n) blocks of size sqrt(n). If you store b[i] = prefix[i-1]-a[i] then you update, you need to decrease b[pos] and increase b[pos+1, n]. So for every block store this: all possible values of b, lazy value what is needed to be added, and some king shaman. So you need to fix the block with index i/block_size. And then for every following blocks add value to lazy, and find some shaman using lazy value and some map for all values of b.

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

      Thought about the prefix minus value and look for zero, but got stuck on n*n solutions. Really cool! Thanks :D

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

    other sqrt decomp solution: http://codeforces.com/contest/992/submission/39380451

    Main idea:

    in some block , we will keep values of form val[pos] — block_sum[pos — 1] and we sort them

    1) to update val[pos] = x, we update block of x only (just recalc the values)

    2) for query, we go through all blocks b1, b2.... bk (which takes O(k = number of blocks))

    Say you have sum of first p blocks. Binary search for that sum in block bp+1. If it exists in block bp+1, we have a king shaman

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

      Wow man! This is quite amazing that this is working! Tried compiling it with std::map and got a tle. but using vector of sized 64 apparently is a gamechanger — worked with a time of 1300ms...! sorting once and doing a binary search using bit is a-bit wow haha but kudos it's amazing you got this to work.

      I got quite intriguied by the idea and played with it a lot ( you can see the last 50+- submissions of mine haha...), This is the best working version I got:

      64-decomposition + your efficient binary search + memory reuse + arrays instead of vectors. http://codeforces.com/contest/992/submission/39407122 1263 ms

      Does anyone have an idea why the 64 "magic" works? trying to use 256 or 512 which are closer to the sqrt(2e5) is way better complexity wise, but works like hell. Cache misses?

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

Thanks for the delightful problems.

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

Did anyone else here get tle on test 132 in problem D?
Here is what I did:
Since the product increases very fast, for every end index I found the starting index such that p > 2e18 in by iterating over every element. Meanwhile, I updated the count of required segments. It takes at most log(2e18) time. For cases when the elements are 1, I checked in O(1).
my code
What can be the possible mistake?

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

In problem C(div2),is there any rule of thumb while taking modulo.Where should i put modulo and when.Also some people took x%mod and k%(mod-1).Taking k%mod gives incoorect answer.Can anyone explain.

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

It was one of the most interesting contests that I had participate before thanks for this great contest ^_^

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

39389999

i was iterating over accepted submissions on the problem E and I've seen that one that i can't understand why it's not getting tle... if we have an array of zeroes and in each query we change the last element to something ...

the segment tree is obviously okay but the "beriz" function seems not okay to me at least ...

because its iterating over all segments that they're min is not positive and go down until the length of the segment is 1 and in my array his function i think will iterate over all elements of the array so that the order seems to be o(n*n)

someone plz help me with my problem ...

these code got ac so it's correct but i don't know why ...

i know the solution of the problem since I've got ac !

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

    His solution is O(n^2) and TL (works more than 5 minutes) on test like this:
    n = 1e5, q = 1e5
    a_i = 0
    p_i = 1, x_i = 0.

    If I'm not wrong, I guess, authors tests aren't strong enough.

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

    Shot dead!

    Ralsei nice catch (your test is now #95).

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

Can someone explain algo to use in div.2 D? Seems like editorial is taking time :).

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

    An easier version that helps inspire a solution for the original problem: What if the smallest number in a[] becomes 2? That brute force tag seems fishy.

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

E solution w/ parallel binary search + segment tree since only sqrt-decomp solution is revealed here:

First step: Reduce the constraint a little bit — Let's say the shamans are claimed as "god-kings" if they have powers at least as much as their predecessors (instead of being exact). Note that the god-king set is a superset of the original king set, so we can check all elements of god-kings to see whether they are exactly kings.

How large is the god-king set? O(lg 1e9). Why? Consider all god-kings (i) in the set, observe that power[i] > sum(power[0:i]), so the power of the next god-king must be at least sum(power[0:i]) + power[i] >= 2*power[i-1], i.e. roughly twice as powerful as the previous one (except in constant corner cases, eg: sample 2, power[0] = power[1] = 2 results in both shamans being god-kings but no.2 is not twice as powerful as the previous god-king), thus the log factor in the complexity.

Now you'd just apply segment tree / BIT to support sum(power[0:i]) queries, and find the first element which is larger than sum(power[0:i]) with parallel binary search.

39403776

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

    I think my solution is similar to yours . Why it gets TL at test 8 ? Thx.

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

      The segment tree query function for sum query is a bit off, it misses a line which returns the sum directly if the current segment completely lies within the current range.

      if(l <= Node[u].l && Node[u].r <= r) return Node[u].sum;

      39407362

      Something it's still wrong though.

      Edit -- And long long. 39407764

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

        Oh..Thanks.I typed the wrong segment tree and i haven't noticed that . I deleted some useless optimization and gets ac. Thanks again

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

Утро уже было. Где разбор?

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

i got A in 2 mins i got B in 99 mins i got C in 93 mins but wrong (sad face) i am in 6th grade