hiho-hihoCoder挑战赛29-A-序列的值
来源:互联网 发布:在线二次元av淘宝 编辑:程序博客网 时间:2024/06/07 13:18
ACM模版
描述
题解
最开始我有一个误区,就是以为子序列必须连续,后来发现不连续也是可以的(尽管就算知道这一点,我也做不出来)……
然后呢,根据题目中的条件我们可以知道,我们必须求出来对于每一个元素他前边有多少个合法的子序列再异或他后结果变大,这时,我们应该考虑,如何才能保证他变大呢?
这个部分虽然不好想,但是很容易理解的是,当这个元素的最高二进制位对应前边序列的异或值的二进制位为
说到这里,剩下的应该就没有什么难点了,我们需要维护一个
说到这里,忽然感觉和单调栈的几道题十分相似,比如说 51Nod 上的那几道,《数组的宽度》之类的题,都是将子连续序列的价值之和转化为了每个元素的贡献之和了,当然这个题是子序列不是子连续序列,所以呢,不能用单调栈而是用
代码
#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;const int MAXN = 1e5 + 10;const int MAX_DIG = 31;const int MOD = 998244353;int n, ans = 0;int a[MAXN];int power[MAXN];int c[MAX_DIG + 3][2];void init(){ power[0] = 1; for (int i = 1; i <= n; i++) { power[i] = (ll)power[i - 1] * 2 % MOD; }}int main(){ scanf("%d", &n); init(); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 0; i <= MAX_DIG; i++) { c[i][0] = 1; } for (int i = 1, j; i <= n; i++) { for (j = MAX_DIG; j >= 0; j--) { if (a[i] & (1 << j)) { break; } } ans += (ll)c[j][0] * power[n - i] % MOD; ans %= MOD; for (j = 0; j <= MAX_DIG; j++) { int t0 = c[j][0]; int t1 = c[j][1]; if (a[i] & (1 << j)) { c[j][0] = (t0 + t1) % MOD; // 选 a[i] 的有 t1 种 不选 a[i] 的有 t0 种 c[j][1] = (t0 + t1) % MOD; // 选 a[i] 的有 t0 种 不选 a[i] 的有 t1 种 } else { c[j][0] = t0 * 2 % MOD; // 选或不选 a[i] 都是 t0 种 c[j][1] = t1 * 2 % MOD; // 选或不选 a[i] 都是 t1 种 } } } printf("%d\n", ans); return 0;}
阅读全文
0 0
- hiho-hihoCoder挑战赛29-A-序列的值
- hiho-hihoCoder挑战赛29-D-不上升序列
- hiho-hihoCoder挑战赛29-B-快速乘法
- hihocoder Challenge 29 A.序列的值
- hihoCoder挑战赛29 D.不上升序列
- hihoCoder挑战赛14 A 不等式
- hihoCoder挑战赛29
- hiho 挑战赛16 A.王胖浩与三角形
- hiho挑战赛17 A String Problem I
- hihoCoder挑战赛A题——顺子
- hihoCoder挑战赛19 A Rikka with Sequence
- hihoCoder挑战赛14A题 1223
- 【hiho挑战赛24 A&B&C】贪心和期望dp惨烈的后缀自动机
- Hihocoder 挑战赛
- hihoCoder挑战赛20 (区间最值)
- hihocoder 挑战赛13A 组合数学中的帕斯卡公式
- hihoCoder挑战赛15 Best Route in a Grid
- hihoCoder挑战赛16 A—— 王胖浩与三角形
- 关于WeX5的carousel控件如何清除图片和增加图片
- js实现图片预览的几种方式
- jade入门
- 计蒜客 网页跳转
- 使用flex图文混排
- hiho-hihoCoder挑战赛29-A-序列的值
- 约瑟夫环问题
- Record: C++命名规则
- 开个新博客 准备搞 2d,3d游戏了 delphi 的 顺便写一下教程,防止以后忘记
- http://write.blog.csdn.net/postedit
- http://write.blog.csdn.net/postedit
- TensorFlow Note 1 : Getting Started With TensorFlow
- VMware Ubuntu安装详细过程
- java 常用三大集合类