2020牛客暑期多校训练营（第五场）解题报告 | Bill Yang's Blog

# 路终会有尽头，但视野总能看到更远的地方。

0%

## A.Portal

### 题目描述

You are now in a big factory. The factory could be recognized as a graph with n vertices and m edges. Every edge has its length. You have k missions to do. The i-th mission is going to vertex $a_i$ , picking a block and then sending it to vertex $b_i$ . You should complete the missions in the order from 1-st to k-th. Initially you are standing at vectex 1.

You have a gun in your hand. When you are at some vertex u, you could shoot the gun at the ground, and then a portal will be built at vertex u. When there are two portals in the factory, assuming they are at u and v, you could transfer between u and v with no cost(just like an edge connecting u and v with length 0).

You also have a remote controller in your hand. It allows you to close a portal whenever you want and wherever you are(closing one portal at a time, not all portals at the same time). What’s more, there could be at most two existing portals. So if you want to create another portal when there exists two, you must use your controller to close one before you create.

You need to find the minimum distance you have to walk in order to complete all k missions.

## B.Graph

### 题目描述

Mr. W got a new graph with N vertices and N - 1 edges. It’s a connected graph without cycles. Each edge should have an ugly value. To make the graph more beautiful, Mr. W hope you can help him modify it. You can delete or add one edge with an ugly value at a time and you can do it as many times as you want. But the following conditions should be satisfied at any time:

1. The graph is connected.
2. For each cycles in the graph, the XOR sum of all ugly values in the cycle is 0.

Mr. W wants to know the minimum sum of ugly values of all edges in the graph.

### 题目分析

1. 求异或方程组
2. $d[i]=i$到根的距离

## C.Eazy

### 题目描述

Mr. W is writing sequences. If he writes two positive integer sequences A and B with length K which satify $\sum_{i = 1}^{K} a_i = N ,\ \ \ \sum_{i = 1}^{K} b_i = M$, he will get $P = \prod_{i=1}^K min(a_i, b_i)$ points.
You want to know the sum of total points he can get in all possible sequences he can write.

## D.Drop Voicing

### 题目描述

Inaka composes music. Today’s arrangement includes a chord of nn notes that are pairwise distinct, represented by a permutation $p_{1 \dots n}$ of integers from $1$ to $n$ (inclusive) denoting the notes from the lowest to the highest.

Her friend, Miyako, sneaks in and plays a trick by altering the chord with the following two operations:

• Drop-2: Take out the second highest note and move it to the lowest position, i.e. change the permutation to $p_{n-1}, p_1, p_2, \dots, p_{n-3}, p_{n-2}, p_n$.
• Invert: Take out the lowest note and move it to the highest position, i.e. change the permutation to $p_2, p_3, \dots, p_{n-1}, p_n, p_1$.

Any number of consecutive Drop-2 operations is considered a multi-drop. Miyako would like to change the permutation to an ordered permutation, $1, 2, \dots, n$,in the fewest number of multi-drops possible. Please help her find the number of multi-drops needed.

### 题目分析

• 将最后一个数插入到另一个位置
• 旋转序列构成的环

• 将某一个数插入到另一个位置

$O(n^2\log n)$即可解决问题，也可以$O(n^3)$或者$O(n^2)$解决问题（留给读者思考，滑稽）。

## F.DPS

### 题目描述

When you are playing multiplayer games, you may want to show that you are the MVP of your team — or blame the one always wandering and watching away from the storm center. Well, there’re statistics that show you preformance, but sometimes numbers speak softer than charts. Now, you’re hired to write a program that output ASCII art histograms showing damage dealt to enemies.
There are n players in the game. Given that the i-th player dealt $d_i$ damage to enemies where $\max_i d_i > 0$ is granted, you need to calculate the number $s_i$ of spaces in the bar by the following foluma:
$s_i = \lceil 50 \frac {d_i} {\max_i d_i} \rceil$
Instead of formal definition of bar description, we will give an example. For some player i whose $s_i = 7$ and $d_i = 777$, the bar is shown as:

Moreover, you have to mark the player with maximal damage dealt to enemies by replacing the last space into ‘*’. If there’re multiple maximum, mark all of them.
See samples for more ideas.

## H.Interval

### 题目描述

Mr. W have a sequence A with length N.
$F(l,r) = A_l\&A_{l+1}\&…\&A_r$
Set $S(l,r) = \{ F(a,b)\ | min(l, r)\leq a \leq b \leq max(l, r) \}$
Mr.W makes Q queries. For each query he wants to know the size of S(L,R) for given L, R.
L, R will not be given directly. He will give you L’ and R’.
$L = (L’ \oplus lastans) \% N + 1$
$R = (R’ \oplus lastans) \% N + 1$
$\oplus$ means XOR.
Lastans donates the answer of last query. It’s zero at the beginning.