Codeforces Good Bye 2023
A. 2023
正常签到。
void solve() {
int n, k, ok = 1;
cin >> n >> k;
int t = 2023;
while(n --) {
int x;
cin >> x;
if(t % x) ok = 0;
t /= x;
}
cout << (ok ? "YES\n" : "NO\n");
if(ok) {
cout << t << ' ';
for(int i = 1; i < k; ++ i) cout << '1' << ' ';
cout << '\n';
}
}
B. Two Divisors
情况一:\(b \bmod a \neq 0\),答案为 \(lcm(a, b)\)。
情况二:\(b \bmod a = 0\),则答案为 \(p \cdot lcm = p \cdot b\),\(p\) 为一个小于 \(a\) 的质数。
由于题目保证 \(a, b\) 是最大两个因子,因此 \(\dfrac{b}{a}\) 为一个小于 \(a\) 的质数。
所以满足题意的一个答案为 \(\dfrac{b}{a} \cdot b\)。
void solve() {
ll a, b;
scanf("%lld%lld", &a, &b);
printf("%lld\n", b % a == 0 ? b / a * b : lcm(a, b));
}
C. Training Before the Olympiad
简化题面:在数组中选两个数,将这两个数合并为 \(\lfloor\dfrac{a[i]+a[j]}{2}\rfloor \times 2\),求在最优操作下,最后剩下数是什么。
先手要使最后结果尽可能大,后手要使最后结果尽可能小。
- 最终答案最大为 $ \sum a[i]$
- 操作后的整个数一定是偶数。
- 后手可以通过选取一奇一偶使答案减一。
现在思路就非常清晰了。
情况一:当前数组中奇数的数量为 \(1\),那么先手必选两个偶数,后手必选这个奇数。
情况二:当前数组中奇数的数量为 \(2\),那么先手必选这两个奇数,后手不能使答案变小。
情况三:当前数组中奇数的数量为 \(3\),那么先手必选两个奇数,后手必选剩下的一个奇数。
由此我们可以发现答案与奇数个数 \(\bmod 3\) 有关。
void solve() {
int n;
cin >> n;
vector<ll> a(n + 1, 0), b(n + 1, 0);
for(int i = 1; i <= n; ++ i) cin >> a[i], b[i] = b[i - 1] + (a[i] % 2), a[i] += a[i - 1];
cout << a[1] << ' ';
for(int i = 2; i <= n; ++ i) {
cout << a[i] - b[i] / 3 - (b[i] % 3 == 1) << ' ';
}
cout << '\n';
}
D. Mathematical Problem
- 我们要构造的是 \(\lceil \dfrac{n}{2} \rceil\) 位数的平方。
- \((1 \ldots 3 \ldots)^2\) 一定是 \((1 \ldots 6\ldots9 \ldots)^2\)
- \((3 \ldots 1 \ldots)^2\) 一定是 \((9 \ldots 6\ldots1 \ldots)^2\)
- \((14 \ldots)^2)\) 一定是 \((196 \ldots)\)
发现上述三种情况很好地契合本题要求。
现在检验这些情况的数目是否 \(\ge n\)。
情况一:以 \(1\) 为首元素枚举后面的位置,共 \(\lfloor \dfrac{n}{2} \rfloor\) 种。
情况一:以 \(3\) 为首元素枚举后面的位置,共 \(\lfloor \dfrac{n}{2} \rfloor\) 种。
情况一:共 \(1\) 种。
加起来共 \(n\) 种,非常完美。
void solve() {
int n, cnt = 0;
cin >> n;
if(n == 1) cout << "1\n";
else {
int len = n / 2 + 1;
for(int i = 0; i < len - 1; ++ i) {
cout << '1';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '6';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '9';
for(int j = 1; j < n - 2 - i * 2; ++ j) cout << '0';
cout << '\n';
}
for(int i = 0; i < len - 1; ++ i) {
cout << '9';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '6';
for(int j = 0; j < i; ++ j) cout << '0';
cout << '1';
for(int j = 1; j < n - 2 - i * 2; ++ j) cout << '0';
cout << '\n';
}
cout << "196";
for(int i = 0; i < n - 3; ++ i) cout << '0';
cout << '\n';
}
}
E. Happy Life in University
int val[N << 2], tag[N << 2];
void build(int x, int l, int r) {
val[x] = tag[x] = 0;
if(l == r) return;
int mid = l + r >> 1;
build(x << 1, l, mid), build(x << 1 | 1, mid + 1, r);
}
void pushup(int x) {
val[x] = max(val[x << 1], val[x << 1 | 1]);
}
void pushdown(int x) {
tag[x << 1] += tag[x], tag[x << 1 | 1] += tag[x];
val[x << 1] += tag[x], val[x << 1 | 1] += tag[x];
tag[x] = 0;
}
void modify(int x, int l, int r, int a, int b, int delta) {
if(a <= l && r <= b) {
tag[x] += delta;
val[x] += delta;
return;
}
pushdown(x);
int mid = l + r >> 1;
if(mid >= a) modify(x << 1, l, mid, a, b, delta);
if(mid < b) modify(x << 1 | 1, mid + 1, r, a, b, delta);
pushup(x);
}
int query(int x, int l, int r, int a, int b) {
if(a <= l && r <= b) return val[x];
pushdown(x);
int mid = l + r >> 1, ret = 1;
if(mid >= a) ret = max(ret, query(x << 1, l, mid, a, b));
if(mid < b) ret = max(ret, query(x << 1 | 1, mid + 1, r, a, b));
return ret;
}
long long ans;
int n, a[N];
int dfn[N], out[N], timestamp;
int lst[N]; //在x的祖先中离x最近的颜色相同的点
vector<int> G[N], e[N]; //e为在x子树中离x最近的颜色相同的点
void dfs(int x) { //枚举lca
dfn[x] = ++ timestamp;
if(lst[a[x]]) e[lst[a[x]]].push_back(x);
int tmp = lst[a[x]];
lst[a[x]] = x;
for(auto y : G[x]) dfs(y);
lst[a[x]] = tmp; //还原last
out[x] = timestamp; //[dfn[x], out[x]]为整棵子树对应序列
modify(1, 1, n, dfn[x], out[x], 1);
for(auto y : e[x]) modify(1, 1, n, dfn[y], out[y], -1);
int mx = 1;
for(auto y : G[x]) {
int t = query(1, 1, n, dfn[y], out[y]);
ans = max(ans, 1ll * mx * t);
mx = max(mx, t);
}
}
void solve() {
cin >> n;
for(int i = 1; i <= n; ++ i) G[i].clear(), e[i].clear();
for(int i = 2, p; i <= n; ++ i) {
cin >> p;
G[p].push_back(i);
}
for(int i = 1; i <= n; ++ i) cin >> a[i];
build(1, 1, n);
ans = 1, timestamp = 0, dfs(1);
cout << ans << '\n';
}
F. Group Division
void Tarjan(int x) {
dfn[x] = low[x] = ++ timestamp;
int cnt = 0;
for(int y : G[x]) {
if(!cs[y]) {
if(!dfn[y]) {
Tarjan(y);
low[x] = min(low[x], low[y]);
if(low[y] >= dfn[x]) {
if(x != root || ++ cnt > 1) cut[x] = true;
}
}
else low[x] = min(low[x], dfn[y]);
}
}
}
void clear_part() {
for(int i = 1; i <= n; ++ i) {
dfn[i] = low[i] = cut[i] = 0;
}
timestamp = 0;
}
void clear_all() {
for(int i = 1; i <= n; ++ i) {
dfn[i] = low[i] = cut[i] = cs[i] = 0;
G[i].clear();
}
timestamp = 0;
}
void solve() {
cin >> n1 >> n2 >> m;
n = n1 + n2;
for(int i = 1; i <= m; ++ i) {
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
for(int T = 1; T <= n1; ++ T) {
for(int i = 1; i <= n; ++ i) {
if(!cs[i]) {
Tarjan(root = i);
break;
}
}
for(int i = 1; i <= n; ++ i) {
if(!cs[i] && !cut[i]) {
bool ok = false;
for(int y : G[i]) ok |= cs[y];
if(ok || T == 1) {
cs[i] = 1;
break;
}
}
}
clear_part();
}
for(int i = 1; i <= n; ++ i) if(cs[i]) cout << i << ' '; cout << '\n';
for(int i = 1; i <= n; ++ i) if(!cs[i]) cout << i << ' '; cout << '\n';
clear_all();
}
Codeforces Good Bye 2023的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- codeforces Good Bye 2015 B. New Year and Old Property
题目链接:http://codeforces.com/problemset/problem/611/B 题目意思:就是在 [a, b] 这个范围内(1 ≤ a ≤ b ≤ 10^18)统计出符合二进制 ...
- Codeforces Good Bye 2015 D. New Year and Ancient Prophecy 后缀数组 树状数组 dp
D. New Year and Ancient Prophecy 题目连接: http://www.codeforces.com/contest/611/problem/C Description L ...
- Codeforces Good Bye 2015 C. New Year and Domino 前缀和
C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...
- Codeforces Good bye 2015 B. New Year and Old Property dfs 数位DP
B. New Year and Old Property 题目连接: http://www.codeforces.com/contest/611/problem/B Description The y ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- codeforces Good Bye 2013 379D New Year Letter
题目链接:http://codeforces.com/problemset/problem/379/D [题目大意] 告诉你初始字符串S1.S2的长度和递推次数k, 使用类似斐波纳契数列的字符串合并的 ...
- Codeforces Good Bye 2016 题解
好久没有fst题了...比赛先A了前4题然后发现room里有人已经X完题了没办法只能去打E题,结果差一点点打完...然后C题fst掉了结果就掉rating 了...下面放题解 ### [A. New ...
- Codeforces Good Bye 2018
咕bye 2018,因为我这场又咕咕咕了 无谓地感慨一句:时间过得真快啊(有毒 A.New Year and the Christmas Ornament 分类讨论后等差数列求和 又在凑字数了 #in ...
随机推荐
- r-nacos v0.4.0版本发布
r-nacos是一个用 rust重新实现的nacos. r-nacos比java实现的nacos更轻量.快速.稳定:合适在开发.测试.受资限服务等环境平替nacos服务使用. r-nacos v0.4 ...
- KingbaseES 可更新的视图
可更新视图 可简化视图可自动更新:系统将允许在视图上使用 INSERT.UPDATE 和 DELETE 语句,就像在常规表上一样.如果视图满足以下所有条件,就是可简化视图,则视图可自动更新: 该视图的 ...
- 正则表达式 (?<= 与 (?= 的区别
(?=pattern) 正向肯定预查,在任何匹配pattern的字符串开始处匹配查找字符串.这是一个非获取匹配, 也就是说,该匹配不需要获取供以后使用.例如,"Windows(?=95|98 ...
- 5W1H聊开源之Why——为什么要参与开源?
中国开源的发展速度发展加快,个人和组织对于为开源作贡献有着前所未有的激情.据<2020年IT行业项目管理调查报告>,约四成受访者以自己开发开源项目.为他人提交项目代码.作为成员开发维护项目 ...
- 官宣!禅道与极狐(GitLab)达成深度合作,携手推进开源开放DevOps生态发展
近日,禅道与著名编程开源开发平台极狐(GitLab)公司签署战略合作,双方将重点探索适用于中国用户DevOps全生命周期解决方案,并将在开源培训和教育.云服务解决方案等多个领域深度合作,共同助力国内D ...
- LLM面面观之MoE
1. 背景 根据本qiang~最新的趋势观察,基于MoE架构的开源大模型越来越多,比如马斯克的Grok-1(314B), Qwen1.5-MoE-A2.7B等,因此想探究一下MoE里面的部分细节. 此 ...
- #Kruskal,可撤销并查集#CF891C Envy
题目 给出一个 \(n\) 个点 \(m\) 条边的无向图,每条边有边权,共 \(Q\) 次询问, 每次给出 \(k_i\) 条边,问这些边能否同时在一棵最小生成树上. 分析 考虑最小生成树选择的边权 ...
- #树套树,二维线段树#HDU 4819 Mosaic
题目 多组数据,给定一个\(n*n\)的矩阵(\(n\leq 80,a_{i,j}\leq 10^9\)) 多组询问一个以\((x,y)\)为中心,边长为\(L\)的子矩阵最大值\(mx\)和最小值\ ...
- 陈海波:OpenHarmony技术领先,产学研深度协同,生态蓬勃发展
11月4日,以"技术筑生态,智联赢未来"为主题的第二届OpenHarmony技术大会在北京隆重举办.本次大会由OpenAtom OpenHarmony(简称"Open ...
- HDC2021技术分论坛:HarmonyOS低代码开发介绍
作者:sunyuhui,wangxiaoyan,华为2012实验室软件IDE专家 什么是低代码开发?低代码开发主要特点有哪些?如何利用低代码开发原子化服务?本文带你一探究竟~ 一.什么是Harmony ...