正文
增加 73 行删除 0 行
451 行未改动全部展开45245345445545645745845914 行未改动474475476477478479480481970 行未改动全部展开14521453145414551456145714581459791 行未改动全部展开225122522253225422552256225722581,164 行未改动全部展开451 行未改动全部展开::::::::::info[代码]```cpp line-numbers#define ask queryint d[N], f[N], a[N];void solve(int N) {14 行未改动for (int i = 1; i <= N; i++) a[i] = N - a[i] + 1;for (int i = 1; i <= N; i++) answer(i, a[i]);}```:::::### [P12202 [COI 2022] 回文子串 / Madioničar](https://www.luogu.com.cn/problem/P12202)970 行未改动全部展开cout << "!" << endl, cin >> q;for (int l, r; q--; ) cin >> l >> r, cout << ans[l][r] << endl;}```:::::### 【未完成】[QOJ18206 Guess the Permutation](https://qoj.ac/problem/18206)791 行未改动全部展开```:::::### [CF1061F Lost Root](https://www.luogu.com.cn/problem/CF1061F)> 这是一道交互题。>1,164 行未改动全部展开451 行未改动全部展开45245345445545645745845946014 行未改动475476477478479480481482483970 行未改动全部展开145414551456145714581459146014611462791 行未改动全部展开2254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023311,164 行未改动全部展开451 行未改动全部展开::::::::::info[代码]```cpp line-numbers#define ask queryint d[N], f[N], a[N];void solve(int N) {14 行未改动for (int i = 1; i <= N; i++) a[i] = N - a[i] + 1;for (int i = 1; i <= N; i++) answer(i, a[i]);}```:::::### [P12202 [COI 2022] 回文子串 / Madioničar](https://www.luogu.com.cn/problem/P12202)970 行未改动全部展开cout << "!" << endl, cin >> q;for (int l, r; q--; ) cin >> l >> r, cout << ans[l][r] << endl;}```:::::### 【未完成】[QOJ18206 Guess the Permutation](https://qoj.ac/problem/18206)791 行未改动全部展开```:::::### [QOJ23600 Invisible Edges](https://qoj.ac/problem/23600)> 这是一道通信题。>> - A:给定一个 $n$ 个点的无根森林,需要传递序列 $a_1 \sim a_n$,值域 $[1,2n]$。> - B:给定 $n$ 和标号打乱的 $a$ 序列,还原森林的所有边。>> 多测,$\sum n \le 2 \times 10^5$。:::::success[题解]利用括号序和有标号有根森林双射。对于 A,任意定根后 DFS 得到括号序,并将 $u$ 的左括号下标作为 $a_u$。B 收到 $b_1 \sim b_n$ 表示,新标号为 $i$ 的点,左括号下标是 $b_i$。将 $b_i$ 的位置设为 `(`,其余位置为 `)`,B 即可还原括号串。从左往右扫,维护一个栈,容易还原森林形态。::::::::::info[代码]A:```cpp line-numbersconst int N = 2e5 + 5;int n, m, num, a[N], vis[N];vector<int> e[N];void dfs(int u, int fa) {vis[u] = true, a[u] = ++num;for (int v : e[u]) if (v != fa) dfs(v, u);++num;}void _main() {cin >> n >> m;for (int i = 1; i <= n; i++) e[i].clear();for (int i = 1, u, v; i <= m; i++)cin >> u >> v, e[u].pb(v), e[v].pb(u);num = 0, fill(vis + 1, vis + n + 1, 0);for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i, -1);for (int i = 1; i <= n; i++) cout << a[i] << " \n"[i == n];}```B:```cpp line-numbersconst int N = 4e5 + 5;int n, b[N], s[N], fa[N], id[N];void _main() {cin >> n;fill(s + 1, s + 2*n + 1, 1);for (int i = 1; i <= n; i++) cin >> b[i], s[b[i]] = 0, id[b[i]] = i;vector<int> st;for (int i = 1; i <= 2*n; i++) {if (s[i] == 0) fa[i] = st.empty() ? 0 : st.back(), st.pb(i);else st.pop_back();}vector<pair<int, int>> e;for (int i = 1; i <= n; i++)if (fa[b[i]]) e.pb(i, id[fa[b[i]]]);cout << e.size() << '\n';for (auto [u, v] : e) cout << u << ' ' << v << '\n';}```:::::### [CF1061F Lost Root](https://www.luogu.com.cn/problem/CF1061F)> 这是一道交互题。>1,164 行未改动全部展开