#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
voideachT(){ int n, m; cin >> n >> m;
if (m < 40 && (n >= (1ll << m))) { cout << -1 << endl; } else { auto check = [&](int x) { ll sum = 0; ll now = 1; ll cnt = m; while (cnt && now < x) { sum += now; now *= 2; cnt--; } sum += cnt * x; return sum >= n; }; int l = 1, r = n; while (l <= r) { int mid = l + r >> 1; if (check(mid)) { r = mid - 1; } else { l = mid + 1; } } cout << l << endl; } }
// u,v 的最近公共祖先 intlca(int u, int v){ while (top[u] != top[v]) { if (dep[top[u]] > dep[top[v]]) u = parent[top[u]]; else v = parent[top[v]]; } return dep[u] > dep[v] ? v : u; }
// u 到 v 的路径长度 intdist(int u, int v){ return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }
// u 是否是 v 的祖先 v 是否在 u 的子树中 boolisAncester(int u, int v){ return dfn[u] <= dfn[v] && dfn[v] < dfnR[u]; }
// u 的 k 级祖先 intkthAncester(int u, int k){ if (dep[u] < k) return-1; int d = dep[u] - k; while (dep[top[u]] > d) { u = parent[top[u]]; } return seq[dfn[u] - dep[u] + d]; }
// 找 u 朝向 v 的第一个儿子 intgetSon(int u, int v){ if (dep[u] > dep[v]) return-1; returnkthAncester(v, dep[v] - dep[u] - 1); }
// 查询 u 节点的子树 Info queryTree(int u){ return seg.query(dfn[u], dfnR[u]); }
// 修改 u 节点 voidapplyNode(int u, constint& d){ seg.apply(dfn[u], d); }
vector<int> subtree(int u){ vector<int> res; for (int i = dfn[u]; i < dfnR[u]; i++) { res.push_back(seq[i]); } return res; } };
intmain(){ int t; cin >> t;
while (t--) { int n; cin >> n;
Tree<int> S(n); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--; v--; S.add(u, v); } S.work(0);
Tree<int> T(n); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--; v--; T.add(u, v); } T.work(0);
ll res = 0; auto dfs = [&](auto&& dfs, int u, bool keep) -> void { // 遍历轻子树 递归求解所有轻子树内部的答案 for (auto& v : S.E[u]) { if (v != S.E[u].front()) { dfs(dfs, v, false); } } // 遍历重子树 递归求解重子树内部的答案 if (S.E[u].size()) { dfs(dfs, S.E[u].front(), true); } res += T.queryTree(u); T.applyNode(u, 1); // 遍历轻子树 求解当前节点 u 关于其子树信息的答案 for (auto& v : S.E[u]) { if (v != S.E[u].front()) { for (auto x : S.subtree(v)) { if (T.isAncester(u, x)) { res += T.queryTree(u) - T.queryTree(T.getSon(u, x)); } } for (auto x : S.subtree(v)) { T.applyNode(x, 1); } } } // 不保留对 info 的影响 回溯前删除 if (!keep) { for (auto x : S.subtree(u)) { T.applyNode(x, -1); } } }; dfs(dfs, 0, true);
using P = complex<double>; #define xx real() #define yy imag()
voideachT(){ int n; cin >> n;
vector<P> p(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; p[i] = P(x, y); }
int a, b, c; cin >> a >> b >> c; if (a) { auto alpha = arg(P(b, -a)); P x0(-1.0 * c / a, 0); for (int i = 0; i < n; i++) { P tmp = p[i] - x0; tmp = polar(abs(tmp), arg(tmp) - alpha); p[i] = tmp + x0; } } elseif (b) { double y0 = -1.0 * c / b; for (int i = 0; i < n; i++) { p[i] -= P(0, y0); } }
auto check = [&](double r) { double lmax = -1e18, rmin = 1e18; for (int i = 0; i < n; i++) { if (sgn(r - abs(p[i].yy)) < 0) { returnfalse; } double d = sqrt(r * r - p[i].yy * p[i].yy); lmax = max(lmax, p[i].xx - d); rmin = min(rmin, p[i].xx + d); if (sgn(rmin - lmax) < 0) { returnfalse; } } returntrue; };
double l = 0, r = 1e6; for (int _ = 0; _ < 50; _++) { double mid = (l + r) / 2; (check(mid) ? r : l) = mid; } cout << l << endl; }
minp[1] = 1; for (int i = 2; i < N; i++) { if (!minp[i]) { minp[i] = i; prime.push_back(i); } for (auto p : prime) { if (i * p >= N) { break; } minp[i * p] = p; if (p == minp[i]) { break; } } }
int n; cin >> n; vector<int> w(n), c(n); for (int i = 0; i < n; i++) { cin >> w[i]; } for (int i = 0; i < n; i++) { cin >> c[i]; }
int ans = 1; for (int i = 0; i < n; i++) { vector<int> factor; while (w[i] > 1) { int x = minp[w[i]]; while (w[i] % x == 0) { w[i] /= x; } factor.push_back(x); }
int res = 1; for (auto x : factor) { // f[素因子 p][最大 0/ 次大 1][颜色 0/ 值 1] if (c[i] != f[x][0][0]) { res = max(res, f[x][0][1] + 1); } if (c[i] != f[x][1][0]) { res = max(res, f[x][1][1] + 1); } } for (auto x : factor) { if (c[i] != f[x][0][0]) { if (res > f[x][0][1]) { f[x][1] = f[x][0]; f[x][0] = {c[i], res}; } elseif (res > f[x][1][1]) { f[x][1] = {c[i], res}; } } else { if (res > f[x][0][1]) { f[x][0] = {c[i], res}; } } assert(f[x][0][0] != f[x][1][0]); } ans = max(ans, res); } cout << ans << endl;
vector<bitset<N>> a(n); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; a[i][j] = x; } }
vector<bitset<N>> c(n); for (int i = 0; i < n; i++) { for (int j = 0; j < p; j++) { int x; cin >> x; c[i][j] = x; } }
vector<bitset<N>> ha(N); vector<bitset<N>> hc(N); for (int i = 0; i < n; i++) { auto insert = [&] { for (int bit = 0; bit < m; bit++) { if (a[i].test(bit)) { if (ha[bit].none()) { for (int rua = bit + 1; rua < m; rua++) { if (ha[rua].any() && a[i].test(rua)) { a[i] ^= ha[rua]; c[i] ^= hc[rua]; } } for (int rua = 0; rua < bit; rua++) { if (ha[rua].test(bit)) { ha[rua] ^= a[i]; hc[rua] ^= c[i]; } } ha[bit] = a[i]; hc[bit] = c[i]; returntrue; } a[i] ^= ha[bit]; c[i] ^= hc[bit]; } } return c[i].none(); }; if (!insert()) { cout << "No" << endl; return0; } }
cout << "Yes" << endl; vector<bitset<N>> b(m); for (int i = 0; i < m; i++) { for (int bit = 0; bit < m; bit++) { if (ha[i].test(bit)) { b[i] = hc[bit]; break; } } }
for (int i = 0; i < m; i++) { for (int j = 0; j < p; j++) { cout << b[i][j] << " "; } cout << endl; }
usingnamespace std; using ull = unsignedlonglong; using ulll = unsigned __int128;
constexpr ull inf = 0x3f3f3f3f3f3f3f3f;
ull ceil(ull n, ull m){ return (n + m - 1) / m; }
ostream& operator<<(ostream& os, ulll n) { string s; while (n) { s += '0' + n % 10; n /= 10; } ranges::reverse(s); return os << s; }
intmain(){ int t; cin >> t;
while (t--) { ull a, b, k; cin >> a >> b >> k;
ulll res = inf; res *= res; for (int _ = 0; _ < 2; _++) { for (ull l = a, r = a; r >= 1; r = l - 1) { l = ceil(a, ceil(a, r)); ull u = l * ceil(a, l); ull v = l * ceil(b, l); if (u <= a + k && v <= b + k) { res = min(res, (ulll)u / l * v); } } swap(a, b); } cout << res << endl; }
for (int p = 1; p < N; p++) { for (int i = p; i < N; i += p) { factor[i].push_back(p); } }
vector<int> l(N), r(N); // x' 可以由 x in l[x']-r[x'] 得到 for (int i = 1; i < N; i++) { auto it = ranges::upper_bound(factor[i], m); it--; int p = *it;
l[i] = i - p / 2; r[i] = i + (p - 1) / 2; l[i] = max(l[i], 0); r[i] = min(r[i], N - 1); } l[0] = 0; r[0] = (m - 1) / 2;
RMQ<int, less<>> L(l); RMQ<int, greater<>> R(r);
while (q--) { int x, y; cin >> x >> y; auto solve = [&](int x, int y) { int l = y, r = y; ll ans = 1; for (;;) { int nl = L(l, r + 1); // 扩张一次 int nr = R(l, r + 1); if (nl == l && nr == r) { // 扩张失败 return-1ll; } if (nl <= x && x <= nr) { return ans; } l = nl, r = nr; ans += 1; } return ans; }; cout << solve(x, y) << endl; } return0; }
(止步于此)
题解说要倍增,恍然大悟。连续多次操作是可以打包的。直接把复杂度降低为log? 级别,? 是操作次数。显然操作次数不会超过2N,现在管他有没有神秘定理都不可能 T 了。
for (int _ = 1; _ < 20; _++) { auto rmq1 = L.back(); auto rmq2 = R.back(); vector<int> l(N), r(N); for (int i = 0; i < N; i++) { l[i] = rmq1(rmq1(i, i + 1), rmq2(i, i + 1) + 1); r[i] = rmq2(rmq1(i, i + 1), rmq2(i, i + 1) + 1); } L.push_back(l); R.push_back(r); }
while (q--) { int x, y; cin >> x >> y; int l = y, r = y; ll ans = 1; for (int bit = 19; bit >= 0; bit--) { int nl = L[bit](l, r + 1); int nr = R[bit](l, r + 1); if (nr < x || x < nl) { l = nl, r = nr; ans += 1ll << bit; } } if (ans == (1 << 20)) { cout << -1 << endl; } else { cout << ans << endl; } } return0; }