Loading

Hello 2026 A ~ F

A

唐诗。

B

猜一手,然后考虑鸽巢原理,答案为 \(\min(\text{mex}(a), k)\)

C

最终占领的是一个区间,枚举左端点然后双指针。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 i128;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 998244353;
template<typename T>
void dbg(const T &t) { cout << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {
    cout << arg << ' ';
    dbg(args...);
}
namespace Loop1st {
int n, m, k;
void main() {
    cin >> n >> m >> k;
    int l = k - 1, r = n - k, ans = 0;
    for (int i = l, j = 0; i >= 0; i--) {
        while (j < 0 || j <= r && (i << 1) - 1 + max(0, j - i) + j <= m) j++;
        j--;
        if (j >= 0 && (i << 1) - 1 + max(0, j - i) + j <= m) ans = max(ans, i + j);
    }
    cout << ans + 1 << '\n';
}

}
int main() {
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Loop1st::main();
    return 0;
}
// start coding at
// finish debugging at

D1

调整法可证。

点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 i128;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 998244353;
template<typename T>
void dbg(const T &t) { cout << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {
    cout << arg << ' ';
    dbg(args...);
}
namespace Loop1st {
int n, dep[N], cnt[N], ans, fa[N];
basic_string<int>e[N], c[N];
void dfs(int u) {
    c[dep[u]] += u;
    cnt[dep[u]]++;
    if (cnt[dep[u]] > ans) {
        ans = cnt[dep[u]];
    }
    for (int v : e[u]) if (v != fa[u]) {
        dep[v] = dep[u] + 1;
        fa[v] = u;
        dfs(v);
    }
} 
void main() {
    ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) e[i].clear(), c[i].clear(), cnt[i] = 0;
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        e[u] += v; e[v] += u;
    }
    dep[1] = 1;
    dfs(1);
    for (int i = 1; i <= n; i++) {
        if (cnt[i] == ans) {
            int fl = 0, ok = 0;
            for (int u : c[i]) {
                if (!fl) fl = fa[u];
                else if (fl != fa[u]) { ok = 1; break; }
            }
            if (!ok) { ans++; break; }
        }
    }
    cout << ans << '\n';
}

}
int main() {
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Loop1st::main();
    return 0;
}
// start coding at
// finish debugging at

D2

场上脑子太迟钝了,直接构造就过了。

E

场上 ABC 做太久 E 没时间想了,首先啥结论都没有这题基本上做不出来的,那猜一手最大是 \(1\)。考虑放缩:

\[\sum \text{lcm}(a_i, a_{i + 1}) \]

\[=\sum \frac{\gcd(a_i, a_i + 1)}{a_ia_{i + 1}} \]

\[\le\sum \frac{a_{i + 1} - a_i}{a_ia_{i+1}} \]

\[=\frac{1}{a_1} - \frac{1}{a_2} + \frac{1}{a_2} - \frac{1}{a_3} + \cdots + \frac{1}{a_{n - 1}} - \frac{1}{a_n} + \frac{\gcd(a_1, a_n)}{a_1a_n} \]

\[\le\frac{1}{a_1} - \frac{1}{a_n} + \frac{a_1}{a_1a_n} \]

\[=\frac{1}{a_1} \]

\[\le 1 \]

取等:\(a_1 = 1, \gcd(a_i, a_{i + 1}) = a_{i + 1} - a_i\),即 \(\exists d \mid a_i, a_{i + 1} = a_i + d\)。直接 DP 可以做到 \(\mathcal{O}(nm \ln m)\)

点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 i128;
typedef pair<int, int> pii;
const int N = 3e3 + 10, mod = 998244353;
template<typename T>
void dbg(const T &t) { cout << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {
    cout << arg << ' ';
    dbg(args...);
}
namespace Loop1st {
int n, m, a[N], f[N][N];
basic_string<int>buc[N];
void main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) buc[i].clear();
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) f[i][j] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	if (a[1] > 1) {
		cout << "0\n";
		return ;
	}
	for (int d = 1; d <= m; d++) {
		for (int x = d; x <= m; x += d) {
			if (x + d <= m) buc[x] += x + d;
		}
	}
	f[1][1] = 1;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= m; j++) if (f[i][j]) {
			if (!a[i + 1]) {
				for (int k : buc[j]) {
					f[i + 1][k] = (f[i + 1][k] + f[i][j]) % mod;
				}
			} else if (a[i + 1] > j && j % (a[i + 1] - j) == 0) f[i + 1][a[i + 1]] = (f[i + 1][a[i + 1]] + f[i][j]) % mod;
		}
	}
	int ans = 0;
	for (int i = 1; i <= m; i++) ans = (ans + f[n][i]) % mod;
	cout << ans << '\n';

}

}
int main() {
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Loop1st::main();
    return 0;
}
// start coding at
// finish debugging at

F

平方显然组合意义。\(f_{i, j}\) 表示一个从 \(i\) 开始走,一个从 \(j\) 开始走的方案数,从 \(f_{p, q}\) 转移来则 \(p, q\)\(u\) 子树内,是一个矩形,考虑倒着做后缀和即可。时间复杂度 \(\mathcal{O}(n^2)\)

点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 i128;
typedef pair<int, int> pii;
const int N = 5e3 + 10, mod = 998244353;
template<typename T>
void dbg(const T &t) { cout << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {
    cout << arg << ' ';
    dbg(args...);
}
namespace Loop1st {
int n, idx, L[N], R[N], rk[N], f[N][N], s[N][N];
char str[N];
vector<int>e[N];
void dfs(int u, int fa) {
    L[u] = ++idx; rk[idx] = u;
    for (int v : e[u]) if (v ^ fa) dfs(v, u);
    R[u] = idx;
}
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int sub(int x, int y) { return x - y + mod >= mod ? x - y : x - y + mod; }
void cadd(int &x, int y) { x += y; if (x >= mod) x -= mod; }
int ask(int x1, int y1, int x2, int y2) {
    return sub(add(s[x1][x2], s[y1 + 1][y2 + 1]), add(s[x1][y2 + 1], s[y1 + 1][x2]));
}
void main() {
    idx = 0;
    cin >> n >> (str + 1);
    for (int i = 1; i <= n; i++) e[i].clear();
    for (int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        e[u].push_back(v); e[v].push_back(u);
    }
    dfs(1, 0);
    for (int i = n; i; i--) {
        for (int j = n; j; j--) {
            if (str[rk[i]] == str[rk[j]]) {
                s[i][j] = add(ask(L[rk[i]] + 1, R[rk[i]], L[rk[j]] + 1, R[rk[j]]), 1);
            }
            cadd(s[i][j], sub(add(s[i + 1][j], s[i][j + 1]), s[i + 1][j + 1]));
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ask(L[i], R[i], L[i], R[i]) << " \n"[i == n];
    }
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) s[i][j] = 0;
}

}
int main() {
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Loop1st::main();
    return 0;
}
// start coding at
// finish debugging at
posted @ 2026-01-08 20:17  循环一号  阅读(5)  评论(0)    收藏  举报