Qingyu's blog

By Qingyu, history, 3 years ago, In English

Let's discuss problems here.

  • Vote: I like it
  • +95
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
  Vote: I like it +34 Vote: I do not like it

Is there an official editorial? If not, then how to solve J?

»
3 years ago, # |
  Vote: I like it +19 Vote: I do not like it

How to solve problem D? MO algorithms gives TLE. I have an idea with Merge Sort Tree(as segment tree,but we store elements) . Will it pass ?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +37 Vote: I do not like it

    We solved D with Mo's Algorithm in under 2s. The idea is to have purely $$$O(Q \sqrt N)$$$ complexity (no log factor). You can do that with linked lists and undo (change inserions to erase and adapt Mo's Algo accordingly).

    Solution
  • »
    »
    3 years ago, # ^ |
    Rev. 3   Vote: I like it +37 Vote: I do not like it

    We used Mo algorithm with linked list over sorted segment. Deletion from linked list is $$$\mathcal{O}(1)$$$ and you use rollbacks to insert elements. To make this work with Mo algorithm sort queries by $$$(r/B, l, r)$$$. Then for each block you have $$$l \in [0, r)$$$ and $$$r \in [B * block, (B+1)*block)$$$, so insert all items from range $$$[0, (B+1)*block)$$$ into linked list, then to handle each query in sorted order you:

    1. Permanently remove some elements from left side
    2. Temporarily remove some elements from right side
    3. Retrieve answer
    4. Rollback all deletions from right side
»
3 years ago, # |
  Vote: I like it +39 Vote: I do not like it

How to solve problems G from Div1 and M from Div2 ? Our team thought may be random will work for M.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +35 Vote: I do not like it

    My Solution for Div.2 M: Let's shuffle the given permutation. The interactor is not adaptive, so we can assume that each location has an equal probability of containing a treasure, assuming it is $$$p$$$. Suppose we examine the first 20 locations in turn, then the probability that the first 20 positions do not contain any treasure is $$$(1-p)^{20}$$$. If this happens, then we can assume that $$$p$$$ is sufficiently small, so that among the remaining positions, we can assume that the probability of picking any two positions, both of which contain the treasure is small ($$$p^2$$$). Then, we perform about 20 more queries, choosing 2 adjacent positions for each queries. There is a $$$p^2$$$ probability of missing the answer. But since $$$p$$$ is small enough, $$$p^2$$$ is also small enough. If we still do not find an answer, then we consider the distribution of the treasure to be more sparse, and continue to increase the number of locations per query. The limit on the number of queries does not appear to be strict, and can be passed by taking a random reasonable set of strategies. Code

»
3 years ago, # |
  Vote: I like it +31 Vote: I do not like it

Is there any div.2 editorial available?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +37 Vote: I do not like it

    Problem A~K are the same as Div.1 problems

    Div.2 L: The Euler characteristic shows that $$$V-E+F-C=1$$$ on any planar graph $$$G$$$. So we have $$$C=V-E$$$ and the answer is simply $$$\max(n-m,0)$$$

    Div.2 M: here

    Div.2 N: After convert each portkey to intervals, the problem is essentially the same as CF786B. There will be up to $$$5n+m$$$ endpoints of the interval, but only $$$n+m$$$ of them will be useful. Code

    Div.2 O: The distance of the two points is just $$$d=|x_1-y_1|+|x_2-y_2|$$$, and note that the given graph is a bipartite graph, so the given condition is equivalent to $$$d \geq w$$$ and $$$d\equiv w \pmod 2$$$.

»
3 years ago, # |
  Vote: I like it +39 Vote: I do not like it

For problem K, we had the following algorithm (which gave WA, but we apparently had a proof of):

Root the tree at any vertex which is not a leaf ($$$n = 2$$$ is handled manually), and order leaves in pre-order. Then we will try to pair up leaves such that all paths go through one common vertex (not necessarily that root). This can be done by, say, pairing up the leaves $$$0, \lfloor m/2 \rfloor$$$, $$$1, 1 + \lfloor m/2 \rfloor$$$ and so on, and pair the last leaf with the first leaf.

Our proof was based on the fact that the vertices that are in a path but not in the previous path form at most two chains, and if we root the tree at the common vertex of all such paths, then the chains are no longer candidates for the thief's position.

Could someone point out a counterexample to this algorithm if the proof sounds wrong?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +26 Vote: I do not like it

    The problem is that leaf $$$\lfloor m/2 \rfloor$$$ can be in the middle of a subtree. If you first scan half of the subtree, then later the other half, the bad guy could move between the two parts of the subtree.

»
3 years ago, # |
  Vote: I like it +23 Vote: I do not like it

Is there somewhere better explanation of problem I? It seems that a lot of important details skipped in the Editorial's explanation.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +38 Vote: I do not like it

    Assume that the drunkard is at position $$$x$$$, and let $$$\mathrm{dp}_{i,j}$$$ denote the probability of being at moment $$$i$$$ and passing through position $$$x+j$$$ at least once. Obviously $$$x$$$ does not affect the answer, so we only need to focus on the relative distance we are from the end point at each moment. We have $$$dp_{i,0}=1$$$, and $$$\mathrm{dp}_{i,j}=p \cdot \mathrm{dp}_{i+1,j}+(1-p) \cdot \mathrm{dp}_{i+1,j-a_{i+1}}$$$, so we can calculate all $$$\mathrm{dp}_{*,*}$$$ in $$$O(n^2)$$$.

    It's easy to observe that if the relative distance(signed) between the end point and the start point is $$$x$$$, then the probability of passing through $$$x$$$ at least once is just $$$\mathrm{dp}_{0,x}$$$, and the answer is $$$\frac{1}{2n+1} \sum_{i} \mathrm{dp}_{0,i}$$$. Code

»
3 years ago, # |
  Vote: I like it +33 Vote: I do not like it

how to get an account?

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    You should probably ask one of closest sector's admin or register new sector. All information is here.

»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it

In problem G, it is not clear how to build the convex hull as for the set of points from example, it will be the monotonous ascending function. Is there any other explanations for problem G ? Endagorion Qingyu

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +13 Vote: I do not like it

    My teammates just checked 50 points around)) I don't know why it works.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +18 Vote: I do not like it

      AmDer Can you send your solution ?

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it +18 Vote: I do not like it

        Wow, it's 32 in the last send!

        Solution
  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Maybe someone from Div.1 will be able to explain this problem ?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +34 Vote: I do not like it

      When we iterate $$$c$$$ over $$$X$$$ in ascending order, the slope of some lines increases. All we need to do is add a new line to the corresponding position. This can be done by using Li Chao Tree or convex hull trick.

      • »
        »
        »
        »
        3 years ago, # ^ |
          Vote: I like it -26 Vote: I do not like it

        Know, everything is clear for me about convex hull trick. But how that function is corresponded to this trick ? Where is k,b,x ? Qingyu Endagorion

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it -26 Vote: I do not like it

          And what does this function fc(y) mean? As far I understand it doesn't count loose. Qingyu

        • »
          »
          »
          »
          »
          3 years ago, # ^ |
            Vote: I like it -18 Vote: I do not like it

          I would be thankful, if someone, maybe from Div1 will help me to understand the solution.

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you Qingyu,mtw! It is clear now.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +44 Vote: I do not like it

    google convex hull trick

»
3 years ago, # |
Rev. 2   Vote: I like it +11 Vote: I do not like it

Can anyone share the code for Problem B? I don't understand the last part of the editorial