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

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

Привет, Codeforces!

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

Задачи на этот раунд придумывали и готовили мы, ученики московской школы №2007, Дмитрий DmitryGrigorev Григорьев и Фёдор ---------- Ушаков. Большое спасибо Андрею 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
  • Проголосовать: не нравится

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

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

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

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

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

score distribution ?

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

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -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.

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

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

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

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

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

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

hoping to see more of mathematics ,all time favorite GreenGrape

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

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

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

Expecting a good contest....

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

Score distribution?

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

Too keked

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

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

»
8 лет назад, скрыть # |
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.

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

Wtf, math contest.

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

Mathforces Round #489 (Div. 2)

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

What is unexpected verdict when trying to hack problem C?

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

Drunken and sleepy ㅜ_ㅜ

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

How to solve div-2 B?

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

How to solve Div 2 B ?

  • »
    »
    8 лет назад, скрыть # ^ |
    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

    • »
      »
      »
      8 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 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
  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

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

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

      • »
        »
        »
        »
        8 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +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.

  • »
    »
    8 лет назад, скрыть # ^ |
    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
  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 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

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

How to solve D?

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

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

    If somebody solved like this, then please help how!

  • »
    »
    8 лет назад, скрыть # ^ |
    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..

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 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.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +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?

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

worst contest with no creativity

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

Was E square root decomposition?

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

Guys look at last two places :o

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

pretest #12 of C? any idea?

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

PS: Found mistake . It doesnt work, Sorry

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

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

»
8 лет назад, скрыть # |
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.

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

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

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

I don't like math problems.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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.

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

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

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

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

What was Test case 4 for C?

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

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

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

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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???

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

RIP ratings.

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

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

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

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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?

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

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

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

div2B was not made for div2B.

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

Problem E was really nice.

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

How to solve DIV2 C?

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

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

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

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +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).

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -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)).

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

What was test case 5 for c?

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

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

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

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

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

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

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

Why is the system testing happening so slow?

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

pretest 5 in B? Coldnt pass it

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

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

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

The math skills...

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

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

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

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

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

the writer of problem B is germa 66 fan

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

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

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

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

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 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

    • »
      »
      »
      8 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 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.

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

  • »
    »
    8 лет назад, скрыть # ^ |
    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.

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

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

»
8 лет назад, скрыть # |
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...

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +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 (?

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

How calculate lcm in Div2 B?

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

can anyone explain D ??

»
8 лет назад, скрыть # |
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.)

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +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);
    }
    
»
8 лет назад, скрыть # |
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. :|

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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 :)

  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +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.

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

    other sqrt decomp solution: http://mirror.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

    • »
      »
      »
      8 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 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://mirror.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?

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

Thanks for the delightful problems.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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.

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

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +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 !

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

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

»
8 лет назад, скрыть # |
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

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

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

»
8 лет назад, скрыть # |
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