当前位置:网站首页>[ARC092B] Two Sequences
[ARC092B] Two Sequences
2022-07-30 13:17:00 【心怀凉月】
[ARC092B] Two Sequences
细节超多,开始找不到任何数据结构维护。
考虑比较暴力的做法。
对答案每一位分别考虑,设当前考虑到第 i i i 位。
计算所有数模 2 i + 1 2^{i + 1} 2i+1 的余数,并升序排序使其满足单调性。(以下都按余数讨论)
若对于一个数 a a a,有数 b b b 满足 ( a + b ) m o d 2 i + 1 ≥ 2 i (a+b)\bmod 2^{i+1}\geq 2^i (a+b)mod2i+1≥2i,则 a , b a,b a,b 原数之和第 i i i 位为 1 1 1。
那么对于每个 a i a_i ai 分类讨论:
- 若 a i ≤ 2 i − 1 a_i \le 2^{i-1} ai≤2i−1,则答案在 [ 2 i − a , 2 i + 1 − a − 1 ] [2^i-a,2^{i+1}-a-1] [2i−a,2i+1−a−1] 范围内,二分统计个数即可。
- 否则即 a i > 2 i − 1 a_i>2^{i-1} ai>2i−1,则答案在 [ 0 , 2 i + 1 − a − 1 ] ∪ [ 2 i + 1 + 2 i − a , 2 i + 1 − 1 ] [0,2^{i+1}-a-1] \cup [2^{i+1}+2^i-a,2^{i+1}-1] [0,2i+1−a−1]∪[2i+1+2i−a,2i+1−1] 范围内,二分统计个数即可(两区间不交)。
对于每一位的总个数判断奇偶性添加贡献即可。
时间复杂度 O ( n log n log V ) \mathcal O(n\log n\log V) O(nlognlogV)。
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
inline void write(int x)
{
if(x < 0)
{
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
const int _ = 2e5 + 10;
int n, a[_], b[_], c[_], d[_], ans;
signed main()
{
// a[1] = 1, a[2] = 2;
// cout << upper_bound(a + 1, a + 2 + 1, 3) - a;
n = read();
for(int i = 1; i <= n; ++i) a[i] = read();
for(int i = 1; i <= n; ++i) b[i] = read();
for(int x = 30; x >= 0; --x)
{
int nw = 1 << x, t = 0;
for(int i = 1; i <= n; ++i) c[i] = a[i] % (nw << 1);
for(int i = 1; i <= n; ++i) d[i] = b[i] % (nw << 1);
sort(c + 1, c + n + 1), sort(d + 1, d + n + 1);
for(int i = 1; i <= n; ++i)
{
if(c[i] <= nw)
{
// [2^i-a,2^{i+1}-a-1]
int ps1 = upper_bound(d + 1, d + n + 1, (nw << 1) - c[i] - 1) - d - 1;
int ps2 = lower_bound(d + 1, d + n + 1, nw - c[i]) - d - 1;
t += ps1 - ps2;
}
else
{
// [2^{i+1}+2^i-a,2^{i+1}-1]
// [0,2^{i+1}-a-1]
int ps1 = upper_bound(d + 1, d + n + 1, (nw << 1) - 1) - d - 1;
int ps2 = lower_bound(d + 1, d + n + 1, (nw << 1) + nw - c[i]) - d - 1;
t += ps1 - ps2;
ps1 = upper_bound(d + 1, d + n + 1, (nw << 1) - c[i] - 1) - d - 1;
ps2 = lower_bound(d + 1, d + n + 1, 0) - d - 1;
t += ps1 - ps2;
}
}
// cout << nw << ": " << t <<"\n";
if(t & 1) ans |= nw;
}
write(ans), he;
return 0;
}
/* */
边栏推荐
- EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
- Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
- 树形dp小总结(换根,基环树,杂七杂八的dp)
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化箱图、width参数自定义箱图中箱体的宽度
- 学习笔记——七周成为数据分析师《第一周:数据分析思维》
- Lake storehouse which electricity (2) of the project: project using technology and version and the environment
- svg波浪动画js特效代码
- 忆联:激活数据要素价值潜能,释放SAS SSD创新红利
- BUUCTF刷题十一道(06)
- “封号斗罗” 程序员修炼之道:通向务实的最高境界
猜你喜欢
随机推荐
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化(平方、开平方、指数化等函数类似使用)
监控界的最强王者,没有之一!
R语言ggpubr包的ggboxplot函数可视化分组箱图、自定义移除可视化图像的特定对象(移除可视化图像轴坐标轴的刻度线标签文本、both x and y axis ticks labels)
RTSP/Onvif协议视频平台EasyNVR服务一键升级功能的使用教程
How to display an Excel table in the body of an email?
学习笔记——七周成为数据分析师《第一周:数据分析思维》
浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
一本通循环结构的程序设计第一章题解(1)
树形dp小总结(换根,基环树,杂七杂八的dp)
【高等数学】【7】二重积分
[PostgreSQL] - explain SQL分析介绍
大手笔!两所“双一流”大学,获75亿元重点支持!
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
jsArray array copy method performance test 2207300823
【软考软件评测师】基于规则说明的测试技术上篇
Raja Koduri澄清Arc GPU跳票传闻 AXG年底前新推四条产品线
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
Smart pointer implementation conjecture
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)









