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

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

Все задачи подготовлены нами — DmitryGrigorev и ----------.

(Идея задачи — DmitryGrigorev)

Tutorial is loading...

Код — 39423470

(Идея задачи — GreenGrape)

Tutorial is loading...

Код — 39423481

(Идея задачи — ----------)

Tutorial is loading...

Код — 39423497

(Идея задачи — DmitryGrigorev)

Tutorial is loading...

(Идея задачи — DmitryGrigorev)

Код — 39423501

Tutorial is loading...

Код решения I — 39423519

Код решения II — 39418926. Попытайтесь оптимизировать :)

Спасибо tfg за идею и код решения III. Хорошая работа!

Код решения III — 39392321

Разбор задач Codeforces Round 489 (Div. 2)
  • Проголосовать: нравится
  • +130
  • Проголосовать: не нравится

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

In B, you could stop thinking after writing a * b = x * y. Since x, y <= 1e9, you could just brutforce all divisors of x * y (which is (divisor of x * divisor of y) ) and be happy with the same complexity.

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

We can also check a*b > 1e18 by 1.0*a*b > 1e18

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

хех, в задаче B находил за корень все делители (не только простые) числа y, их получалось немного (10^9 их было всего лишь 100). А потом за квадрат комбинировал все (проверял на l, r и другие нужные проверки на gcd, lcm). Хммм... Зашло. Повезло с тестами? http://codepaste.me/f804f38a <- код здесь

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

Nice round, i liked the problems :). may i suggest that you change the problem statement of D slightly from "where p is the product of all integers on the given array" to "where p is the product of all integers in the selected sub-array". the example test cases do clear up the confusion though so it was fine

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

good problems E&D

but as a recommendation for authors, I think the test cases for E weren't strong enough(enough for square-root codes but not for others) since some o(n^2) solutions got ac(see my comment on advertisement blog)!!!

hope it'll never happen again!!!

ps:

my comment on advertisement blog :

http://mirror.codeforces.com/blog/entry/60050#comment-438494

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

For the problem C, can anyone please elaborate how do we get the expected value of dresses at the end of a month?

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

anyone please explain solution of problem D I am not getting it through editorials

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

    First, we'll analyze this problem in an O(n^2) solution:

    Initialize 2 arrays PrefSum[n] and PrefProd[n] in which PrefSum[i] is the sum of first i number in the array, and PrefProd[i] is the product of first i number in the array. After that, we count the subsegment by for loops.

    Looking at this solution, we can easily notice that k*SumOfSegment cannot exceed 10^5*10^8*10^5=10^18, so that ProductOfSegment cannot exceed 10^18<2^60, which means a subsegment can never have 60 or more numbers that greater than 1.

    With this fact, we can reduce the complexity of this solution to only O(n*60).

    The trick here is you have to find the way to skip the 1's in the array using pre-calculated arrays, without leaving out any possible answer. When skipping each group of consecutive 1's, we can prove that there are only at most 1 possible answer between this group. That way, we can keep each loop in O(60) complexity.

    Here's my code (C++14): https://ideone.com/JLNwsZ

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

Actually A can be solved in O(N) where N = 2e5 Just store all negative numbers as

1e5 + abs(a[i])

where a[i] < 0.

Space is increased here but still better than N*log(N) on an average

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

Why does this idea not work for D?

For every array index which is 1 I store the number of 1s after that so that I can directly jump to the next index. (for example, 1 1 3 1 1 1 4 I get 2 1 — 3 2 1 -)

Now a normal nested for loop and if array[i] == 1 then if sum * k was less than prod and after adding no. of 1s following that 1 if sum * k >= prod, answer is incremented.

And normal check for prod == k*sum for elements other than 1.

Simplified Code

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

Can anyone explain the problem E to me? I have trouble understanding the query part? Particularly, We find the leftmost element which may be king-shaman yet. We can realise that it's the leftmost element, which doesn't lie in the good prefix (as there isn't king-shaman according the definition), which have a value at least . It can be done using segment tree with maximums, with descent. The left-most element that may be king is (i+1) ? And how is this O(logN) ? Thanks

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

can somebody tell me, in B why we are running the for loop from i = 1 to i^2 < (y/x)

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

If somebody could tell me why my solution for D gives the wrong answer on Test 133, I would be very grateful.
I keep the positions of the nonzero elements in a vector, traverse this vector, while also keeping a track of the number of ones to the left and the right of the current subsegment we're considering.

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

In Problem E Solution 1,

We can realise that it's the leftmost element, which doesn't lie in the good prefix (as there isn't king-shaman according the definition), which have a value at least p[i]. It can be done using segment tree with maximums, with descent.

How can we find this index in log(N)?

I could only think of (log(n))^2 approach.

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

    Do a maximum query segment tree. When you visit the segments that cover the range, if the maximum element is what you need you go down else just return n. Now, you are in a range that has the answer you need, you just need to decide wether to go left/right. If the maximum element to the left if what you need, go left otherwise go right.

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

      I'm still no clear. Could you please explain a little bit more?
      Here is a snippet of code from solution1:

      int down(int i, int l, int r, LL S){
          if (r-l==1) return l;
          int mid = (l+r)/2;
          if ((LL) rmq_max[2*i+1] >= S) return down(2*i+1, l, mid, S);
          return down(2*i+2, mid, r, S);
      }
      int get(int i, int l, int r, int l1, int r1, LL S){
          if (l1 >= r1) return n;
          if (l==l1 && r==r1){
              if ((LL) rmq_max[i] < S) return n;
              return down(i, l, r, S);
          }
          int mid = (l+r)/2;
          int res = get(2*i+1, l, mid, l1, min(r1, mid), S);
          if (res != n) return res;
          return get(2*i+2, mid, r, max(l1, mid), r1, S);
      }
      LL get_sum(int i, int l, int r, int l1, int r1){
          if (l1 >= r1) return 0;
          if (l==l1 && r==r1) return rmq_sum[i];
          int mid = (l+r)/2;
          return get_sum(2*i+1, l, mid, l1, min(r1, mid)) + get_sum(2*i+2, mid, r, max(l1, mid), r1);
      }
      

      The get method is to find the leftmost element which is larger than value S. And if we ignore the down method called in it, I think the time complexity of it is the same as get_sum since in the worst case the res is n every time and it will call itself twice every time. And now we take down into account. The down method is log(N) itself. So the time complexity of the method should be log(N)^2. How can we tell that the complexity of get is log(N)?

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

        get() visits the "cover" of the range, so the same segments that something like get_sum() would visit. Once it gets to a range that it calls down, it will get an index and will go back returning it (if there's no answer there, it won't call down). So the first part (visiting the ranges that cover the query range) is O(log) and the second part (down) is O(log) too.

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

In problem B , test 7 we have the input 1 1000000000 158260522 158260522, whose answer is 1. How can we have a number b/w 1 and 1000000000 whose hcf is greater than the number itself, shouldn`t the answer be 0.

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

Thanks for such a good contest. I like problems, they are interesting to me and especially I like 3rd solution of E problem.

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

Any sqrt decomposition solution for E passed?

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

In problem B, Is There any efficient way to solve it if the "LCM" condition removed, I mean:

Given three numbers l r x , count number of pairs (a,b) such that l <= a,b <= r and GCD(a,b) = x.

where : (1 ≤ l ≤ r ≤ 10^9, 1 ≤ x ≤ 10^9).

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

Why complexity of problem A is nlogn we are just looping through the n elements then why not O(n) where did logn came from??

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

    If you use a map or set to find how many different numbers there are, you have additional log(n) factor for mapping the values, though it can be done in O(n) using an array instead of those two mentioned above.

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

girlfriend !!!!

FFFFFFFF!!!

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

Here are my solutions to the problems of this contest.

I found problem E quite difficult to understand so I wrote an editorial here. This was for the first approach mentioned in the editorial with the maximum and sum segment tree.

I also loved the third solution presented to E so I provided by own exposition of this bitwise bucket method here.

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

can someone please explain how the grouping is done in the solution 3 of prob E?

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

Контест хороший, таски интересные

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

When didn't pass but O(qlog2nlog(2e9)) does, you realize how fast binary search on fenwick trees really is! 39512053

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

In problem B c*x=a and d*x=y then he said that GCD(c,d) = 1!! is that a proof or this is a rule how should i had known!

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

Can someone explain in solution I of 992E, what is meant by descent:

"We find the leftmost element which may be king-shaman yet. We can realise that it's the leftmost element, which doesn't lie in the good prefix (as there isn't king-shaman according the definition), which have a value at least . It can be done using segment tree with maximums, with descent."

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

Anyone getting WA on test #133? Couldn't identify the problem. My WA submission.