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 如果不是,就需 ...
随机推荐
- gem5 使用记录, 基于理解来写个最简单的计数器程序
学习GEM5其实是因为工作需要,主要是用来做数字电路的模型仿真的,之前用过 systemC,现在公司用的 gem5,其实本质上都是 C++只是套个不同的壳然后拿去仿真而已,SC本身就提供了时钟可以仿真 ...
- Exchange 2019数据库切换
最近在测试Exchange 2019的一些安装步骤.在测试到DAG的数据库切换的时候遇到了一些问题.An Active Manager operation failed. Error: The dat ...
- HBuilder X之uniapp最适合的代码补全模板
{ // 注意:本文档仅支持单行注释,并且'//'前不能有任何非空字符!!! // // HBuilderX使用json扩展代码块,兼容vscode的代码块格式 // 本文档修改完毕,保存即可生效,无 ...
- VLAN的配置
1 vlan的概念和作用 虚拟局域网(VLAN)是一组逻辑上的设备和用户,这些设备和用户并不受物理位置的限制,可以根据功能.部门等因素将它们组织起来.相互之间的通信就好像它们在同一个网段中一样. 虚拟 ...
- Kubernetes 中部署 MySQL 集群
文章转载自:https://www.cnblogs.com/ludongguoa/p/15319861.html 一般情况下 Kubernetes 可以通过 ReplicaSet 以一个 Pod 模板 ...
- 第二章:视图层 - 7:HttpResponse对象
类定义:class HttpResponse[source] HttpResponse类定义在django.http模块中. HttpRequest对象由Django自动创建,而HttpRespons ...
- 在CentO7系统上配置Springboot项目jar包开机自启动
官方文档地址:https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment-ins ...
- Java实现6种常见排序
1.冒泡排序(Bubble Sort) 第0轮 3 1 4 1 5 9 2 6 5 3 5 8 9 第1轮 1 3 1 4 5 2 6 5 3 5 8 9 9 第2轮 1 1 3 4 2 5 5 3 ...
- PHP全栈开发(四): HTML 学习(3. form 表单)
form 表单标签 它表的是一个区域,而非是一个具体的某个元素,它也是作为一个容器的存在. 表单域主要是允许用户在表单域中输入内容,比如文本框,下拉列表,单选框,复选框,等等. <!DOCTYP ...
- HDU2041 超级楼梯 (线性DP)
fn[i]表示走上第i级台阶的所有走法. 方程:fn[i]=fn[i-1]+fn[i-2]; 1 #include<cstdio> 2 #define MAXN 40 3 using na ...