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

Автор hloya_ygrt, история, 7 лет назад, По-русски
Tutorial is loading...
Код автора

First accepted Zhigan.

Tutorial is loading...
Код автора

First accepted polygonia.

Tutorial is loading...
Код автора

First accepted div2: RaidenEi.

First accepted div1: Lewin.

Tutorial is loading...
Код автора

First accepted div2: polygonia.

First accepted div1: V--o_o--V.

Tutorial is loading...
Код автора

First accepted div2: xsup.

First accepted div1: anta.

Tutorial is loading...
Код автора

First accepted: ksun48.

Tutorial is loading...
Код автора

First (and last :DD) accepted: radoslav11.

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

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

O(1) solution is possible for 810A. Link

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

В задаче B дивизиона 2, я сортировал по убыванию min(2 * k[i], l[i]) Почему данный подход не будет работать?

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

    Тест:

    2 1
    10 11
    3 6
    

    Вы увеличите продажи в первый день, получив min(20, 11) + min(3, 6) = 14 единиц.

    Если увеличить во второй день, выйдет min(10, 11) + min(6, 6) = 16 единиц

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

it's good to mention the First accepted

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

Через что нужно пройти, чтобы научиться замечать, что элементы данной мне матрицы равны побитовому XOR строки и столбца, сложенному с единицей? Допустим, этот пример я уже знаю. Тогда в следующий раз будет что-то новенькое...

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

In "809 A — Do you want a date?", the last line of explanation says 2**(i-1) * 2**(n-i-1). I believe it should be (2**i - 1) * (2**(n-i) - 1), i.e. make sure at least one of [1, i] gets picked, and at least one of [i+1,n] gets picked.

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

    Those subsets are allowed to be empty.

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

      x[i+1] - x[i] is added to final answer for all those subsets where there is at least one integer picked from [1,i] and at least one integer picked from [i+1,n]. Note the closed intervals, and the fact that the implementation of the solution is doing what I described.

  • »
    »
    7 лет назад, # ^ |
    Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится
    • "They are adding to the answer xi — xi+1 in all the subsets, in which there is at least one point a ≤ i and at least one point b ≥ i + 1."

    I really don't understand the explanation: if a subset s contains xi and xi + 1 and also contains other two points xa been a ≤ i and xb been b ≥ i+1, as points are sorted xa < xi < xi+1 < xb by definition of  then F(s) = | xb — xa |

    Can someone help me here ?

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

      I meant that I'm dividing the whole range a, a + 1, ..., i, i + 1, ...b in edges between neighbours, so the answer is xb - xa = (xa + 1 - xa) + (xa + 2 - xa + 1) + ... + (xi + 1 - xi) + ...(xb - xb - 1). We add each part separately.

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

        anti-quicksort test ??? seriously ???

        Someone can explain me the point of that test cases ?

        Java use different algorithms just for memory issues not performance.. :(

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

          This test was added automatically when someone hacked someone's solution, so you should always be careful using sort on java.

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

It seems that Div1B has weak data.

http://codeforces.com/contest/810/submission/27251518[My submission]

I made some mistakes on edge cases that I can't pass the data

8 2
4 7

But I didn't fail the system test.How can I add this data?

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

    While the event is in progress, you can challenge, and I am pretty sure that successful challenges are added to final tests (even though I could not find this stated anywhere). I don't think this can be done after the competition ended. One option could be creating a mock competition with that problem, but I am not sure how much you can change the data.

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

Не понимаю почему не проходит 8 тест в задаче 810B — Летняя распродажа. Может кто подскажет ошибку?

http://codeforces.com/contest/810/submission/27267008

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

in Div2E / Div1C can anybody prove me that the cell(i , j) is equal to (i — 1) xor (j — 1 ) + 1 ?

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

    The formulation is just an obfuscated form of Nim with two piles.

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

    I am unable to understand the solution to Div2E / Div1C mentioned above. Can anybody please explain the solution?

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

      I want to join your demand. Can someone, please, give a reference on any valuable information about this type of problems?

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

        I will briefly go through probably the most confusing part of the code

        if(a==1&&A[i]==0&&x==1)continue; // and the two lines follow

        This line ensures that the X values considered for dp are LT/EQ to X, another way of putting this line is:

        if(prefix_is_equal && x > X[corresponding_bit]) then skip this state. //If the prefix is smaller then there are no restrictions to the less significant bits

        The state transit below also makes use of the same idea

        dp[i+1][a&(A[i]==x)][b&(B[i]==y)][c&(C[i]==z)] // and the two lines follow

        a&(A[i] == x) implies that the equality flag remains true iff prefix is equal AND the current bit is equal.

        mul(z<<(30-i),dp[i][a][b][c])

        Just to add the values of sum according to the XOR value and the significant of the bit.

                add(res,solve(x2,y2,k));
                sub(res,solve(x2,y-1,k));
                sub(res,solve(x-1,y2,k));
                add(res,solve(x-1,y-1,k));
        

        Just in case, this is a way of querying 2D plane.

        If you are interested in trying-out similar questions with similar difficulty I'd recommend 747F.

        (These types of DP questions mostly appear as the last Div2 question, it pretty much decides who will be the first of that round as you can see here)

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

          what does the dp and cnt refer to ? same goes for the dp parameters i failed to understand even tho i read the tutorial many times :( can u please clarify :)

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

            dp and sum has the same parameters, namely:

            dp[bitmask position][equality flag for x coord][eq flag for y][eq flag for k]

            bitmask position (i): we are currently evaluating the value of (1<<i), from the most significant to the least, since ...

            eq flags: this represents if the value of {x, y, k} is going to be strictly smaller than our queried upper-bound. If the flag is true, that means we have to be careful of not over-counting stuff because of counting above the upper-bound. If the flag is false, that means the considered value is less than the upper-bound no matter what, so we would consider all transitions.

            The only difference between dp and sum is that dp represents the "ways" of reaching this state, and sum is the weighted value of the dp array.

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

        I have linked a proof for why cell (i, j) has value (i - 1)xor(j - 1) + 1 above.

        Let's make a function sum(i, j, k), which gives the sum of all integers less than or equal to k that are in the upper-left i * j fragment of the matrix. We can use that to calculate the answer for any fragment.
        Sum for fragment (x1, y1, x2, y2) is equal to sum(x2, y2, k) - sum(x1 - 1, y2, k) - sum(x2, y1 - 1, k) + sum(x1 - 1, y1 - 1). If you don't know why, research "2D prefix sum."


        How do we compute the answer for that function efficiently?

        Let's come up with an algorithm for computing sum of all x xor y, such that for each x and y such that x ≤ a and y ≤ b and (x xor y) ≤ k. Using that we can easily compute value of sum().
        Let's define dp function bt() which will compute that value for us (we'll add arguments to that function one by one when we need them). For computing the value, let's add binary digits to possible values of x xor y one by one, starting from the most significant bit. Let's add argument i to function bt(), which is the index of the digit we're currently adding.

        Now, for every digit i, there are 4 possibilities: we make the ith bit of x 0 and of y 0 resulting in 0 for (x xor y), or 1 and 0 resulting in 1, or 0 and 1 resulting in 1, or 1 and 1 resulting in 0.
        But how do we know which of these possibilities is valid (i.e. doesn't result in exceeding the limit for x, y, or (x xor y))?

        Suppose we're adding bit 1 at index i in x (while adding bits one by one from most significant to less significant), which initially doesn't exceed a.x would exceed a if and only if we're adding bit 1 at index i, while the ith bit of a is 0, and suffix starting from bit i + 1 of x in binary representation is equal to suffix starting from bit i + 1 of a in binary representation. UPD: by suffix, I mean bits with index i+1 through MAXLOG, which can also be viewed as prefix depending on how you visualize it. I'll call it suffix in this post. By ith bit, I mean bit (1 << i). If it's unclear for you why that's true, here's an example:

        a = 110110000110
        x = 11011xxxxxxx (so far)
                 ^      
        

        In the above example, we can't add 1, because x would become bigger than a. Note that in this case suffix in a (11011) is equal to suffix in x (11011).

        Another example:

        a = 110110110000
        x = 11001xxxxxxx (so far)
                 ^      
        

        Here, we can safely add 1 without making x exceed a. That is because suffix in a (11011) doesn't equal suffix in x (11001).

        The same goes for y with b and for (x xor y) with k.
        Thus, we only need to keep track of whether the suffix of x currently equals suffix of a, same for y and k. Thus we add 3 boolean arguments to bt, which becomes bt(i, sufA, sufB, sufK).

        Back to the four possibilities: Pairs (1, 0) and (0, 1) result in 1, thus add to answer (1 << i)*numberOfCellsIn(i - 1, newSufA, newSufB, newSufK)*bt(i - 1, newSufA, newSufB, newSufK). Pairs (0, 0) and (1, 1) result in 0, thus just add tp the answer numberOfCellsIn(i, newSufA, newSufB, newSufK)*bt(i - 1, newSufA, newSufB, newSufK).
        We can compute numberOfCellsIn in a fashion similar to bt().

        You can check my code if it's unclear how to compute newSufs. Also check out my code for how to apply that for computing answer of sum, since I'm too lazy to finish this tutorial and I think I already explained the confusing parts and the rest is easy.
        Note that the dp does $lg(max(a, b,y))*2*2*2
        operations, which is sufficient to solve the problem as there are only 10^4 queries.

        My code is too long because I made functions numberOfCellsIn and bt separately, but I think that only makes it clearer.

        Hope that helps

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

          I am very grateful to you. It realy helps.

          However,

          a = 000011011011 x = xxxxxxx11011 (so far) ^
          In the above example, we can't add 1, because x would become bigger than >>a.

          Why cant I add 1 at this place and follow it up with 0 afterwards?

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

            I'm sorry, that should have been reversed, and it should be called prefix instead of suffix. The most significant bit is on the left instead of the right. I'll fix this

            EDIT: Updated

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

          last problem of div 2 explained so easily. thanks

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

27270104 This is my submission to div1 A and it gets wrong answer can someone help please

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

Hey! I tried the problem 809A but got wrong ans.Please can someone suggest what I did wrong?

Code:

#include<bits/stdc++.h> #define MAXN 100010 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 using namespace std; int cmpfunc (const void * a, const void * b) { return ( (int)a — (int)b ); } int main(){ int n,sum=0,power=1; cin>>n; int arr[n]; //set arr:: iterator it,it1; for(int i=0;i<n;i++){ cin>>arr[i]; } sort(arr,arr+n); for(int i=0;i<n-1;i++){ power=1; for(int j=i+1;j<n;j++){ sum+=((arr[j]-arr[i])*(power))%mod; power=(power*2)%mod; } } //it=arr.begin();

cout<<sum%mod<<endl; return 0; // 1 3 4 5 }

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

    It looks like an overflow of int

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

      but i tried with long long int too but still got wrong ans

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

        You need to do modulo operations each time you do any other operation, cause it can lead to long long overflow otherwise. The real answer for this problem can be as big as 2^300000 is big, so the problem requires to print it modulo 10^9 + 7. Furthermore, your solution is not fast enough for passing all tests.

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

Didn't get the tutorial for 809A/810C. Can someone help ?

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

    Tutorial is very confusing. Here is a much simpler solution:

    http://codeforces.com/contest/809/submission/27245918

    What we are doing here is adding up the sum of each point and all the pairs it can make to the left. For any point i, when we transition to point i + 1, we must do dp[i + 1] = dp[i] * 2 + (2^i — 1) * (difference between i + 1 and i), where dp[i] represent the answer if i is the right endpoint. (^ denotes exponentiation) This is because we can view this as adding difference between i + 1 and i to all the intervals, and the 2^i — 1 is because we want to extend the leftmost interval by diff so we must multiply diff by 2^(i — 1) and the leftmost + 1 interval by diff * 2^(i — 2)... and so on, which adds to 2^i — 1.

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

У меня такая беда. Я не могу сдать задачу про угадывания блюд даже тогда, когда я прочитал разбор. Либо моё решение умеет разрешать все случаи, кроме (k==2 && a[0]==1 && a[1]==n-1), либо оно умеет разрешать только этот случай. То есть у меня WA72. (WA74, когда я вбил один тест в программу. ) Я пробовал писать разные границы и разные условия. (Это, наверное, можно просмотреть в посылках.)
То есть я не понимаю, каким образом находится ответ в случае, когда выбраны только блюда под номерами 1 и n. В авторском решении этот случай не рассматривается отдельно, по-видимому, этот код AC-шный. Я не хочу просто копировать его. Также я уже подустал и не могу больше эффективно думать.

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

    Ну, моя последняя посылка перед тем, как я сдался и послал авторский код. (Я уже был уверен, что авторский код не пройдёт тестирование.) http://codeforces.com/contest/810/submission/27279938

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

      Посмотрим на код, получающий WA72.

      Вы находите любое из загаданных блюд, помечая его как x. После этого вы пытаетесь найти y где-то до x. Однако если случится так, что x — самое левое из загаданных блюд, то в y будет лежать мусор. Чтобы проверить, что значение y корректно, в авторском решении есть условие if (!query(y, x). Рассмотрим, что оно делает. Допустим, в y лежит не мусор. В таком случае, ближайшее к y число — y, то есть расстояние равно 0. Так как x найден корректно, то и до него расстояние 0. Так как 0 ≤ 0, ответ на запрос query(y, x) будет равен TAK. Допустим, в y лежит мусор. Тогда ближайшим блюдом к y будет x и, так как y < x (потому что мы искали его в промежутке [1;x-1]), расстояние до y будет строго больше нуля и ответом на такой запрос будет NIE. Таким образом, одним запросом query(y, x) мы сможем проверить, было ли заказано блюдо y. В вашем же решении вы спрашиваете запрос y y + 1, а не y x, что и приводит к неправильному ответу. Так что переписывать тоже нужно уметь.

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

I don't quite understand how does the randomly generated prior value of a node helps maintaining the treap while merging in the implementation of Div1D, would someone mind explaining it to me?

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

    If you are using classic binary tree, its depth could be O(n), if the values come in sorted order. When you are randoming priorities and use them while merging, your depth of tree would be O(logn)

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

In 809C , can someone help to prove that number in (i,j) is [(i-1)XOR(j-1)]+1 ?

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

    The position (i, j) could be regarded as two nim stacks with size of (i-1, j-1), thus the mex value of the set {(a, j) | a < i} + {(i, b) | b < j} is equivalent to the grundy value of the nim state (i-1, j-1), i.e. (i-1) ^ (j-1), plus 1.

    (Search grundy theorem to learn more about the "grundy value")

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

In Problem Div2C/Div1A, we can also count the number of times xi is added and is subtracted from the result. Consequently, the answer becomes the sum of xi * (2^i - 2^(n-1-i)) for i=0,..,n-1.

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

Can someone help me debug this code: This code is for "Do you want a Date?" problem. I am getting the wrong answer for test case 6. This will be a great help.

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

For 809B, the editorial states:

So we always know in which of the halves [l, mid], [mid + 1, r] exists at least one point.

Why is this statement true?

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

    Because if the half doesn't contain a point, it won't give us information, that the closest point is closer than in a half with a point. Why? Because any point in the interval is closer, than any point out.

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

In the solution of Div1 E.Can you tell me how to prove the formula about the coefficients of C ??? Thanks :)

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

Hi guys!
I made a video editorial on the problem 'Glad to meet you'. I couldn't solve it during the contest, so I had to get back at it somehow. :-)
We use binary search to find the two points.

Here is the link: Div 415 — Glad to Meet You

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

Why did 2B disappear? The problem seems to be removed, and tutorial is not available now.

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

Found the mistake. Sorry for bothering.
Can someone point me the mistake in logic in this solution for 810B? I have wrong answer on testcase 15.