BZOJ 4017 小Q的无敌异或
来源:互联网 发布:自己设计房子软件 编辑:程序博客网 时间:2024/06/10 04:29
题目:http://www.lydsy.com/JudgeOnline/problem.php?id=4017
题意:
给定一个长度为
题解:
先考虑第一问。
令
考虑
那么我们可以固定右端点
再考虑第二问。
同第一问的想法,令
考虑答案的第
那么对于每个
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std; typedef long long LL;const int maxn = 100010, mod = 998244353;int n, a[maxn], x[maxn], bit[maxn], ans1;long long s[maxn], p[maxn], ans2;void inc(int &x, int y){ x += y; if(x >= mod) x -= mod;}void add(int x){ for( ; x <= n; x += ~x & x + 1) bit[x] ^= 1;}int sum(int x){ int ret = 0; for( ; x >= 0; x -= ~x & x + 1) ret ^= bit[x]; return ret;}int idx(long long val){ int L = -1, R = n; while(L < R) { int M = L + R + 1 >> 1; if(p[M] <= val) L = M; else R = M - 1; } return L;}int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); x[i] = x[i - 1] ^ a[i]; s[i] = s[i - 1] + a[i]; } for(int k = 0, powk = 1; k < 30; ++k, inc(powk, powk)) { int cnt[2] = {}, tmp = 0; for(int i = 0; i <= n; ++i) { inc(tmp, cnt[((x[i] >> k) & 1) ^ 1]); ++cnt[(x[i] >> k) & 1]; } inc(ans1, (long long)powk * tmp % mod); } for(int k = 0; 1LL << k <= s[n]; ++k) { int tmp = 0; for(int i = 0; i <= n; ++i) p[i] = s[i] & ((1LL << k + 1) - 1); sort(p, p + n + 1); memset(bit, 0, sizeof bit); for(int i = 0; i <= n; ++i) { long long now = s[i] & ((1LL << k + 1) - 1); add(idx(now)); tmp ^= sum(idx(now - (1LL << k))) ^ sum(idx(now + (1LL << k))) ^ sum(idx(now)); } if(tmp) ans2 |= 1LL << k; } printf("%d %lld\n", ans1, ans2); return 0;}
2 0
- BZOJ 4017 小Q的无敌异或
- bzoj 4017 小Q的无敌异或
- xian 区域赛 g bzoj 4017: 小Q的无敌异或
- bzoj 4017 小Q的无敌异或(所有子区间异或的和 与和的异或)
- bzoj4017 小Q的无敌异或 数学
- 【bzoj4017】小Q的无敌异或 树状数组
- 2017.10.12 小Q的无敌异或 失败总结
- BZOJ4017 小Q的无敌异或 好题
- 小Q的无敌异或(第一问)
- bzoj 4813 [Cqoi2017]小Q的棋盘
- BZOJ 4813 [Cqoi2017]小Q的棋盘
- bzoj 4815: [Cqoi2017]小Q的表格
- bzoj 4814 [Cqoi2017]小Q的草稿
- BZOJ 4813 [Cqoi2017]小Q的棋盘
- BZOJ 4018 小Q的幻想之乡
- [BZOJ 4815] [Cqoi2017]小Q的表格 解题报告
- [BZOJ 4813][Cqoi2017]小Q的棋盘:TreeDP
- [几何] BZOJ 4814 [Cqoi2017]小Q的草稿
- js 动作与函数绑定
- How to create a task in the openwrt system, the timer to switch WiFi power。
- jquery悬浮提示框
- 外卖的撕‘哔’大战 Contest2074 - 中南大学第九届大学生程序设计竞赛网络预选赛
- 用java语言和xfire工具写一个简单的webservice并运用
- BZOJ 4017 小Q的无敌异或
- ubuntu安装rabbitmq和python的使用实现
- 利用浮层使select不可选
- H公司工作总结(1)
- python使用rabbitmq实例二,工作队列
- PADS学习之路02-PADS LOGIC概述
- spark:学习杂记Hbase--33
- ireport插入图片
- lfm简单应用