Please read the new rule regarding the restriction on the use of AI tools. ×

ArvinCiu's blog

By ArvinCiu, history, 23 hours ago, In English

A. Meaning Mean

Author: athin
Developer: ArvinCiu
Editorial: Kinon

Tutorial

B. Maximize Mex

Author: joelgun14
Developer: joelgun14, CyberSleeper
Editorial: Pyqe

Tutorial

C. Adjust The Presentation

Author: ArvinCiu
Developer: icebear30, gansixeneh
Editorial: ArvinCiu, gansixeneh

Tutorial

D. Boss, Thirsty

Author: ArvinCiu
Developer: CyberSleeper
Editorial: Pyqe

Tutorial

E. Digital Village

Author: CyberSleeper
Developer: ArvinCiu

Tutorial
  • Vote: I like it
  • +20
  • Vote: I do not like it

»
4 hours ago, # |
  Vote: I like it -10 Vote: I do not like it

Brute force in $$$\mathcal{O}(nm^2)$$$ can pass problem D.

Submission

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    Hacked :)

»
4 hours ago, # |
Rev. 2   Vote: I like it +18 Vote: I do not like it

Segment tree for C2 seems like a bit of overkill. You can keep vector of sets of indices in b for each element of a. (including m+i, or just any large const, if you allow non-strict increasing arrays instead). Then, for each update you just need to check whether the increase condition still holds for the adjacent pairs and update the counter. If the counter is full, yield YA.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

FINALLY.

»
3 hours ago, # |
Rev. 7   Vote: I like it +42 Vote: I do not like it

My solution to E3:

Call a node "special" if it is one of the $$$p$$$ given nodes. Call a node "chosen" if it is one of the $$$k$$$ nodes in the chosen subset.

Build the Kruskal Reconstruction Tree (KRT) of the graph, with $$$2n - 1$$$ nodes. All nodes in the original graph are given the same label in the KRT.

For some special node $$$x$$$, let $$$y$$$ be the lowest ancestor of $$$x$$$ in the KRT with at least one chosen node in the subtree of $$$y$$$. The maximum edge weight needed to get to a chosen node from special node $$$x$$$ in the original graph, is the weight of the edge that corresponds to $$$y$$$ in the KRT.

I then transformed this problem a bit. Let $$$f(i)$$$ be the edge weight that corresponds to node $$$i$$$ in the KRT (if $$$i \leq n$$$, then $$$f(i) = 0$$$). Let $$$g(i)$$$ be the number of special leaves in the subtree of $$$i$$$ in the KRT. Let the the value of a node $$$i$$$ be $$$g(i) * (f(i) - f(par[i]))$$$. Choose $$$k$$$ leaves in the KRT, to minimize the sum of values of nodes which have at least one chosen leaf in its subtree.

This works, because the contribution of some special node $$$x$$$ will be $$$(f(y) - f(par[y])) + (f(par[y]) - f(par[par[y]])) + \dots = f(y)$$$, where $$$y$$$ is the lowest ancestor of $$$x$$$ with a special node in its subtree.

Greedy solution
DP solution
»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

After this round my rating increased to 1399, and i am very grateful to the rating system.

»
98 minutes ago, # |
Rev. 2   Vote: I like it +4 Vote: I do not like it

E is very nice. Learn a new trick about how to use minimum spanning tree in this.
Btw, editorial E only E3 ?!