版本比较
ABC416 全部题目题解
正文
增加 6 行删除 6 行
123455678921 行未改动3132333435353637383930 行未改动7071727374747576777846 行未改动12512612712812912913013113213359 行未改动193194195196197197198199200201114 行未改动全部展开316317318319320320321322323324118 行未改动全部展开### A
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 1000010;21 行未改动直接贪心即可。
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 1000010;30 行未改动直接暴力枚举所有序列,放到 vector 中然后直接排序或者 nth_element 求出字典序第 k 小的字符串即可。
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 1000010;46 行未改动map 恰好可以胜任这个操作,因此初始把 $b$ 中所有元素都放到 map 中然后将 $a$ 中的每一个元素模拟上述流程在 map 中找元素匹配即可。时间复杂度为 $O(n\log n)$ 可以通过该题。
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 1000010;59 行未改动对于机场而言,其最短的做法一定形如:从 $x$ 走到距离其最近的机场 $i$,飞到距离 $y$ 最近的机场 $j$ 然后从 $j$ 走到 $y$,即:$\mathrm{dis}_{x,i}+\mathrm{dis}_{i,j}+\mathrm{dis}_{j,y}$。于是可以记录 $to_i$ 表示距离 $i$ 点最近的机场,然后初始处理 $to$ 数组,松弛完一轮之后直接重新处理 $to$ 即可。时间复杂度仍为 $O(n^2Q)$ 可以通过。
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 1000010;114 行未改动全部展开答案即为 $\max\limits_{i=0}^k\max(f_{1,i,0},f_{1,i,1},f_{1,i,2})$。直接按照上述方法求答案,时间复杂度为 $O(nk^2)$ 可以通过。
```cpp#pragma GCC optimize(3, "Ofast", "inline", "unroll-loops")#include <bits/stdc++.h> #include <bits/stdc++.h>#define int long longusing namespace std;
const int N = 200010;118 行未改动全部展开