Codeforces Round #833 (Div. 2)补题
Codeforces Round #833 (Div. 2)
D. ConstructOR
知识点:高位和对低位无影响
一开始以为和广州的M一样,是数位dp,后来发现只要找到一个就行
果然无论什么时候都要看清题目
这时候还是没有什么思路,然后就看了题解的提示:当a和b有奇数时,d为偶数一定不可以
那显然这个结论可以继续推广,比较a,b,d的二进制后导0的大小即可
当a,b,d都截去d的后导0时,此时d为奇数
那么我们可以再次应用高位计算不会对低位产生影响这个条件
直接观察 \(a|b\) 如果当前第 \(i\) 位的 \(ans\) 与 \(a|b\) 不同时,
在这一位上加上 \(d<<i\) 即可对 \(ans\) 的第 \(i\) 位取反
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
ll a, b, d;
void solve()
{
cin >> a >> b >> d;
int w = __builtin_ctz(d);
if ((a & ((1 << w) - 1)) || (b & ((1 << w) - 1)))
{
cout << -1 << endl;
return;
}
a |= b;
a >>= w;
d >>= w;
ll ans(0);
for (int i = 0; (1ll << i) <= a; i++)
if ((ans ^ a) & (1 << i)) ans += d << i;
cout << (ans << w) << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
rep(i, 1, T) solve();
}
E. Yet Another Array Counting Problem
知识点:笛卡尔树上dp
看的大佬的题解,已经说的很清楚了,我就不献丑了
属实没想到能把题面这么转化,涨见识了
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<int,int>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
template<class T> using vc = vector<T>;
const ll mod = 1e9 + 7;
void solve()
{
int n, m;
cin >> n >> m;
vc<array<int, 2>> h(n + 1);
rep(i, 1, n) h[i][0] = h[i][1] = -1;
vc<int> a(n + 1);
rep(i, 1, n) cin >> a[i];
int sz = (int)log2(1.0 * n);
vc<vc<pii>> f(n + 1, vc<pii>(sz + 1));
rep(i, 1, n) f[i][0] = {a[i], i};
rep(j, 1, sz) for (int i = 1; i + (1 << j) - 1 <= n; i++)
{
pii a = f[i][j - 1];
pii b = f[i + (1 << (j - 1))][j - 1];
if (a.fi >= b.fi) f[i][j] = a;
else f[i][j] = b;
}
auto RMQ = [&](int l, int r)
{
int k = (int)log2(1.0 * r - l + 1);
pii a = f[l][k];
pii b = f[r - (1 << k) + 1][k];
if (a.fi >= b.fi) return a.se;
return b.se;
};
int rt = RMQ(1, n);
function<void(int, int, int)> build = [&](int rt, int l, int r)
{
if (l < rt)
{
int ls = RMQ(l, rt - 1);
h[rt][0] = ls;
build(ls, l, rt - 1);
}
if (r > rt)
{
int rs = RMQ(rt + 1, r);
h[rt][1] = rs;
build(rs, rt + 1, r);
}
};
build(rt, 1, n);
vc<vc<ll>> dp(n + 1, vc<ll>(m + 1));
function<void(int)> dfs = [&](int rt)
{
int ls = h[rt][0], rs = h[rt][1];
if (ls == -1 && rs == -1) rep(i, 1, m) dp[rt][i] = 1;
else if (rs == -1)
{
dfs(ls);
rep(i, 1, m - 1)
dp[rt][i + 1] = (dp[ls][i] + dp[rt][i]) % mod;
}
else if (ls == -1)
{
dfs(rs);
rep(i, 1, m)
dp[rt][i] = (dp[rs][i] + dp[rt][i - 1]) % mod;
}
else
{
dfs(ls), dfs(rs);
rep(i, 1, m)
{
dp[ls][i] = (dp[ls][i] + dp[ls][i - 1]) % mod;
dp[rs][i] = (dp[rs][i] + dp[rs][i - 1]) % mod;
}
rep(i, 1, m)
{
dp[rt][i] = (dp[rt][i - 1] + (dp[rs][i] - dp[rs][i - 1]) * dp[ls][i - 1]) % mod;
dp[rt][i] = (dp[rt][i] + dp[rs][i - 1] * (dp[ls][i - 1] - (i > 1 ? dp[ls][i - 2] : 0))) % mod;
}
}
};
dfs(rt);
ll ans(0);
rep(i, 1, m) ans = (ans + dp[rt][i]) % mod;
if (ans < 0) ans += mod;
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
rep(i, 1, T) solve();
return 0;
}
Codeforces Round #833 (Div. 2)补题的更多相关文章
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #585 (Div. 2) [补题]
前言 2019.9.16 昨天下午就看了看D题,没有写对,因为要补作业,快点下机了,这周争取把题补完. 2019.9.17 这篇文章或者其他文章难免有错别字不被察觉,请读者还是要根据意思来读,不要纠结 ...
- Codeforces Round #786 (Div. 3) 补题记录
小结: A,B,F 切,C 没写 1ll 对照样例才发现,E,G 对照样例过,D 对照样例+看了其他人代码(主要急于看后面的题,能调出来的但偷懒了. CF1674A Number Transforma ...
- Codeforces Round #429 (Div. 2) 补题
A. Generous Kefa 题意:n个气球分给k个人,问每个人能否拿到的气球都不一样 解法:显然当某种气球的个数大于K的话,就GG了. #include <bits/stdc++.h> ...
- Codeforces Round #419 (Div. 1) 补题 CF 815 A-E
A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. ...
- Codeforces Round #590 (Div. 3)补题
要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ∅ √ 解 E 待定 F 传送门 第一 ...
- Codeforces Round #574 (Div. 2)补题
A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 > Σki / 2 ? (n + 1)/2 - Σki / ...
- Codeforces Round #615 (Div. 3) 补题记录
第一次搞CF,结果惨不忍睹...还是太菜了 A:要用到全部的钱,所以总数必须是3的倍数,而且初始状态下任意一人的钱数不能超过总数除以3,否则没法分了 (也就这个签到算是在我能力范围之内了....) # ...
- Codeforces Round #617 (Div. 3) 补题记录
1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需 ...
随机推荐
- 如何从零开始参与 Apache 顶级开源项目?| 墙裂推荐
写在开头 从 2021 开始,有一个很有意思的说法经常在各大技术媒体或开源论坛中出现,「开源正在吞噬一切」.不论是否言过其实,从一个行业从业者的切身感知来看,开源确实从少数极客的小众文化成为主流的 ...
- Zookeeper 分布式事务锁的使用
使用Netflix的包 curator-recipes pom文件引入相关依赖 <dependency> <groupId>org.apache.zookeeper</g ...
- 安装Win 8.1 跳过输入密钥步骤
安装Win 8.1 跳过输入密钥步骤 问题描述 因测试需要,要安装Win 8.1到实体机上,但是制作完U盘启动盘,开始安装时发现,必须输入产品密钥才能进行安装.所以,在这里介绍 ...
- linux下安装mysql(rpm安装)
Mysql 5.7.29安装步骤 1.首先卸载自带的Mysql-libs(如果之前安装过mysql,要全都卸载掉) rpm -qa | grep -i -E mysql\|mariadb | xarg ...
- 2021年3月-第02阶段-前端基础-Flex 伸缩布局-移动WEB开发_flex布局
移动web开发--flex布局 1.0 传统布局和flex布局对比 1.1 传统布局 兼容性好 布局繁琐 局限性,不能再移动端很好的布局 1.2 flex布局 操作方便,布局极其简单,移动端使用比较广 ...
- 从EDR的火热看安全产品的发展
从EDR的火热看安全产品的发展 2021年4月8日23:13 当开始写这篇博客时,外面正是护网进行得如火如荼的时候.作为一个产品经理,在吃瓜的同时,也在思考着安全产品的发展.这几年一些看得到的变化在深 ...
- ProxySQL 审计
1.审计日志 ProxySQL 2.0.5 引入了审计日志.此功能允许跟踪某些连接活动.要启用此功能,需要配置变量 mysql-auditlog_filename,也就是审计日志的文件名.此变量的默认 ...
- 使用 Skywalking Agent,这里使用sidecar 模式挂载 agent
文章转载自:https://bbs.huaweicloud.com/blogs/315037 方法汇总 Java 中使用 agent ,提供了以下三种方式供你选择 使用官方提供的基础镜像 将 agen ...
- Elasticsearch与MySQL对应关系表
MySQL 中的数据库(DataBase),等价于 ES 中的索引(Index). MySQL 中一个数据库下面有 N 张表(Table),等价于1个索引 Index 下面有 N 多类型(Type). ...
- 谣言检测——(PSA)《Probing Spurious Correlations in Popular Event-Based Rumor Detection Benchmarks》
论文信息 论文标题:Probing Spurious Correlations in Popular Event-Based Rumor Detection Benchmarks论文作者:Jiayin ...