版本比较
线性数据结构&其它技巧&字符串学习笔记
正文
增加 31 行删除 31 行
132 行未改动全部展开13313413513613713713813914014114214214314414514638 行未改动1851861871881891891901911921938 行未改动20220320420520620620720820921021121121221321421523 行未改动23924024124224324324424524624711 行未改动259260261262263263264265266267110 行未改动全部展开37837938038138238238338438538654 行未改动441442443444445445446447448449106 行未改动全部展开556557558559560560561562563564108 行未改动全部展开67367467567667767767867968068194 行未改动77677777877978078078178278378378478578678726 行未改动814815816817818818819820821822102 行未改动全部展开92592692792892992993093193293393493593693793893893994094194247 行未改动99099199299399499499599699799820 行未改动10191020102110221023102310241025102610279 行未改动103710381039104010411041104210431044104568 行未改动1114111511161117111811181119112011211122108 行未改动全部展开123112321233123412351235123612371238123939 行未改动127912801281128212831283128412851286128725 行未改动131313141315131613171318131713181319132013211322132313241325132613271327132813291330133165 行未改动13971398139914001401140114021403140414051405140614071408140939 行未改动14491450145114521453145314541455145614572 行未改动14601461146214631464146414651466146714685 行未改动14741475147614771478147814791480148114821483148414851486148714871488148914901491132 行未改动全部展开{ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= m; i++) for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[u].emplace_back(v), g[v].emplace_back(u); eff[u] |= (1ll << v - 1), eff[v] |= (1ll << u - 1); eff[u] |= (1ll << v - 1), eff[v] |= (1ll << u - 1); } for (int i = 1; i <= n; i++) eff[i] |= (1ll << i - 1), tot |= (1ll << i - 1); mid = n >> 1; dfs(1, 0, 0);38 行未改动 if (visr[i] && ys[i]) ans += (1 << ys[i] - 1); mp[change(ans, sumd)]++; return; } if (!visr[p[x].r]) if (!visr[p[x].r]) { int temp = visx[p[x].x]; visx[p[x].x] = true, visr[p[x].r] = true, calc(x + 1, lim, sumd ^ p[x].d), visr[p[x].r] = false, visx[p[x].x] = temp; }8 行未改动 int ans = 0; for (int i = 1; i <= n; i++) if (visr[i] && ys[i]) ans += (1 << ys[i] - 1); ans ^= sumup; for (int i = ans; i; i = (i - 1) & ans) for (int i = ans; i; i = (i - 1) & ans) final += mp[change(i, sumd)]; final += mp[change(0, sumd)]; return; } if (!visr[p[x].r]) if (!visr[p[x].r]) { int temp = visx[p[x].x]; visx[p[x].x] = true, visr[p[x].r] = true, work(x + 1, start, lim, sumd ^ p[x].d), visr[p[x].r] = false, visx[p[x].x] = temp; }23 行未改动 if (!saw) continue; ys[i] = ++tot; } sumup = (1 << tot) - 1; if (!flag) if (!flag) mp.clear(), clear(), calc(1, mid, 0), clear(), work(mid + 1, mid + 1, n, 0); else { int ed = p[mid].x, pos, rgt;11 行未改动{ ios::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) solve(); while (T--) solve(); return 0;}
```110 行未改动全部展开typedef long long ll;int p[N], c[N];typedef pair<int, int> pii;priority_queue<int, vector<int>, greater<int>> delta;priority_queue<pii, vector<pii>, greater<pii>> P, C; priority_queue<pii, vector<pii>, greater<pii>> P, C;bool vis[N];int main(){ ios::sync_with_stdio(0);54 行未改动
我们假定这俩都能算(因题而异。现在考虑怎么二分。斜率上升时,在凸包上切到的点横坐标是单调的,所以说就可以根据当前选了多少二分斜率了。
如何计算答案?我们回到 $g(x) = b + W \cdot x$ 这个式子,由于切点一定是让 $b = g(x) - W \cdot x$ 最大的点,所以说,我们在给所有白边的权值全都加上 $-W$ 以后,自由选择出来的结果,一定是 $b = g(x) - W \cdot x$ 最大的 $x$。就是说,我们不再需要考虑限制,随便选即可得到切点的横坐标,同时我们也得到了这个 $b$ 截距。
然后,我们怎么统计答案?如果选出的 $x \ge k$ 就统计答案,无论如何都要改变二分端点。这就看上面参考资料里面,我切的可能是连续一段斜率相同的地方,而这段区间左端小于 $k$,右端大于 $k$。这个时候我们乘上的就不能是算出的切点 $x$,而是要求的 $k$。于是,最终表现为 $ans = b + W \cdot k$ 这是一直没弄懂的地方。
还有一个点——万一二分的斜率是小数?实际上,我们总能通过给一些属性定义偏序关系(就比方说对这个物品的种类,钦定有限制的这种先选)来避免。
106 行未改动全部展开int ys[1500010];int dot;inline void init(){ for (int j = 1; j <= n; j++) for (int j = 1; j <= n; j++) { sort(lsh[j] + 1, lsh[j] + k + 1); newk[j] = unique(lsh[j] + 1, lsh[j] + k + 1) - lsh[j] - 1; }108 行未改动全部展开}// 下面是主函数block = sqrt(n);for (int i = 1; i <= n; i++) cin >> a[i];for (int i = 1; i <= m; i++) for (int i = 1; i <= m; i++){ cin >> q[i].l >> q[i].r; q[i].id = i;}94 行未改动bool ans[100010];inline void solve(int x, int l, int r){ int end = undo_fa.size(); for (int i = 0; i < tree[x].size(); i++) for (int i = 0; i < tree[x].size(); i++) { int u = tree[x][i].u, v = tree[x][i].v; if (find(u) == find(v)) if (find(u) == find(v)) { undo(end); return; }26 行未改动 cin >> temp.u >> temp.v >> l >> r; if (l < r) modify(1, 1, k, l + 1, r, temp); } solve(1, 1, k); for (int i = 1; i <= k; i++) for (int i = 1; i <= k; i++) if (ans[i]) cout << "Yes\n"; else cout << "No\n"; return 0;}102 行未改动全部展开 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) for (int i = 1; i <= n; i++) { cin >> pp[i].a >> pp[i].b >> pp[i].c; pp[i].cnt = 1; } sort(pp + 1, pp + n + 1, cmpA); int m = 0; for (int i = 1; i <= n; i++) if (pp[i].a == pp[i - 1].a && pp[i].b == pp[i - 1].b && pp[i].c == pp[i - 1].c) p[m].cnt++; else else { p[++m] = pp[i]; p[m].id = m; }47 行未改动那不就好办了,这就相当于对一个 $n$ 维,每维值域 $0/1$ 的数组求一个高维前缀和就行了,复杂度 $O(n \cdot 2 ^ n)$。代码:```for (int i = 0; i < n; i++) for (int j = 0; j < (1 << n); j++) if (j & (1 << i)) if (j & (1 << i)) f[j] += f[j ^ (1 << i)];```看典例:[CF165E](https://www.luogu.com.cn/problem/CF165E)。
20 行未改动 f[a[i]] = i; } for (int i = 0; i < 22; i++) for (int j = 0; j < (1 << 22); j++) if (j & (1 << i) && f[j ^ (1 << i)]) if (j & (1 << i) && f[j ^ (1 << i)]) f[j] = f[j ^ (1 << i)]; for (int i = 1; i <= n; i++) { int temp = ((1 << 22) - 1) ^ a[i];9 行未改动我们发现 $A \subseteq B$ 就是 $\bar B \subseteq \bar A$。那么我们枚举补集 $\bar A$,然后 $f(A \cup \{x\})$ 就可以更新 $f(A)$。那么我们可以直接枚举 $A$(从大到小),如果 $x \notin A$ 就更新即可。这两个枚举方式是完全等价的,代码:```for (int i = 0; i < n; i++) for (int j = (1 << n) - 1; j >= 0; j--) if (!(j & (1 << i))) if (!(j & (1 << i))) f[j] += f[j ^ (1 << i)];```复杂度与子集枚举相同。
68 行未改动 } for (int i = 1; i <= m; i++) cout << border[i] << " "; cout << "\n"; return 0;} }```复杂度证明:考虑 $j$ 的移动:$j$ 只会在适配的时候增加,共增加 $O(S)$ 次;所以说最多减少 $O(S)$ 次,也就是说总共变化 $O(S)$ 次。## Manacher 算法诶,就这个字符串,爽~(爽个毛线根本学不会108 行未改动全部展开using namespace std;const int N = 2e5 + 10;string t[N], s;vector<int> G[N];struct Trie struct Trie{ int deg[N], ans[N], fail[N], g[30][N], tot; inline void bfs() {39 行未改动 uu = trie.g[ch - 'a'][uu]; trie.ans[uu]++; } queue<int> q; for (int i = 1; i <= trie.tot; i++) for (int i = 1; i <= trie.tot; i++) if (!trie.deg[i]) q.push(i); while (!q.empty()) { int u = q.front();25 行未改动 int deg[N], ans[N], tot, g[30][N], fail[N]; inline void bfs() { queue<int> q; for (int i = 0; i < 26; i++) if (g[i][0]) q.push(g[i][0]); for (int i = 0; i < 26; i++) if (g[i][0]) q.push(g[i][0]); while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < 26; i++) if (g[i][u]) fail[g[i][u]] = g[i][fail[u]], q.push(g[i][u]), deg[g[i][fail[u]]]++, G[g[i][u]].emplace_back(g[i][fail[u]]); else g[i][u] = g[i][fail[u]]; } } } inline void clear() { for (int i = 0; i <= tot; i++) {65 行未改动#include <vector>#include <algorithm>#include <stack>#include <queue>#define lowbit(x) ((x) & -(x)) #define lowbit(x) ((x) & -(x))using namespace std;const int N = 1e5 + 10;struct Ask { int x, y, id; };vector<Ask> que[N]; vector<Ask> que[N];int ed[N], now;struct BIT{ int t[N];39 行未改动 cin >> s; int n = s.size(), m; s = " " + s; cin >> m; for (int i = 1; i <= m; i++) for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; que[y].push_back({x, y, i});2 行未改动 sta.push(0); for (int i = 1; i <= n; i++) if (s[i] == 'B') sta.pop(); else if (s[i] == 'P') ed[++now] = sta.top(); else else { if (!acam.g[s[i] - 'a'][sta.top()]) acam.g[s[i] - 'a'][sta.top()] = ++acam.tot; sta.push(acam.g[s[i] - 'a'][sta.top()]); }5 行未改动 { if (s[i] == 'B') bit.add(acam.dfn[sta.top()], -1), sta.pop(); else if (s[i] == 'P') { trtr++; trtr++; for (Ask now : que[trtr]) ans[now.id] = bit.query(acam.dfn[ed[now.x]], acam.dfn[ed[now.x]] + acam.sz[ed[now.x]] - 1); } else { sta.push(acam.g[s[i] - 'a'][sta.top()]); bit.add(acam.dfn[sta.top()], 1); } } } for (int i = 1; i <= m; i++) cout << ans[i] << "\n"; return 0;}```