正文
增加 133 行删除 0 行
451 行未改动全部展开45245345445545645745845914 行未改动474475476477478479480481526 行未改动全部展开10081009101010111012101310141015376 行未改动全部展开13921393139413951396139713981399791 行未改动全部展开219121922193219421952196219721981,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)526 行未改动全部展开```:::::### [ABC355E Guess the Sum](https://www.luogu.com.cn/problem/AT_abc355_e)> 这是一道交互题。>376 行未改动全部展开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 行未改动475476477478479480481482483526 行未改动全部展开10101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077376 行未改动全部展开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)526 行未改动全部展开```:::::### [CodeChef UWCOI20F](https://www.codechef.com/problems/UWCOI20F)> 这是一道交互题。>> 交互库隐藏了一个长为 $n$ 的字符串 $S$。每次询问给出下标 $i$,询问 $z[i]$ 的值,其中 $z$ 是 Z 函数 $z[i]=\text{lcp}(S,S[i:])$。>> 找到最大的 $q$ 使得 $\exists T, S=T^q$。>> $n \le 10^6$,满分询问次数 $9$。:::::success[题解]只要求出 $S$ 的最小整周期 $k \mid n$,返回 $q=\frac{n}{k}$ 即可。根据 Z 函数的性质,我们有 $k \in \text{per}(S) \iff k+z[k]=n$。由周期性质 $k \in \text{per}(S) \land i \in \mathbb{N} \implies i \times k\in \text{per}(S)$。对 $n$ 进行质因数分解 $n=p_1^{\alpha_1} p_2^{\alpha_2}\cdots$,则 $k$ 必能表示为 $p_1^{\beta_1} p_2^{\beta_2}\cdots$ 的形式。取固定的 $i$,注意到 $k$ 的合法性关于 $\beta_i$ 单调,令其余 $\beta_j=\alpha_j$,只对 $\beta_i$ 二分求解。可以证明询问次数 $\sum \log \alpha_i\le 9$。::::::::::info[代码]```cppint mpow(int a, int b) {int res = 1;for (; b; b >>= 1) (b & 1) ? (res *= a) : a, a *= a;return res;}int solve(int n, int q) {auto check = [&](int x) -> bool {if (x == n) return true;return x + query(x) == n;};umap<int, int> a; int x = n;for (int i = 2; 1LL * i * i <= x; i++) {if (x % i) continue;while (x % i == 0) a[i]++, x /= i;}if (x != 1) a[x]++;int res = 1;for (auto [p, c] : a) {int b = n / mpow(p, c);int lo = 0, hi = c, u = 0;while (lo <= hi) {int mid = (lo + hi) >> 1;if (check(b * mpow(p, mid))) u = mid, hi = mid - 1;else lo = mid + 1;}res *= mpow(p, u);}return n / res;}```:::::### [ABC355E Guess the Sum](https://www.luogu.com.cn/problem/AT_abc355_e)> 这是一道交互题。>376 行未改动全部展开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 行未改动全部展开