当前位置:网站首页>[ARC092B] Two Sequences
[ARC092B] Two Sequences
2022-07-30 13:40:00 【With a cool moon】
[ARC092B] Two Sequences
细节超多,Started not finding any data structure maintenance.
Consider a more violent approach.
Consider each answer individually,Let the current take into account the first i i i 位.
Calculate all numbers 2 i + 1 2^{i + 1} 2i+1 的余数,And sort in ascending order to satisfy monotonicity.(The remainder is discussed below)
若对于一个数 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 The sum of the original numbers 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] 范围内,Binary statistics can be counted.
- 否则即 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] 范围内,Binary statistics can be counted(The two intervals do not intersect).
It is enough to add contribution to the judgment of parity for the total number of each bit.
时间复杂度 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;
}
/* */
边栏推荐
猜你喜欢

阿里 P7 到底是怎样的水平?

The way of programmers' cultivation: do one's own responsibilities, be clear in reality - lead to the highest realm of pragmatism

电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM

第十三天笔记

Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD

BUUCTF刷题十一道(06)

外包干了七年,废了。。。

05 | 后台登录:基于账号密码的登录方式(下)

【自校正控制】自校正PID

cpu / CS 和 IP
随机推荐
Eleven BUUCTF questions (06)
Self-tuning PID self-tuning control 】 【
leetcode207.课程表(判断有向图是否有环)
(HR面试)最常见的面试问题和技巧性答复
Mysql batch insert transaction unique key repeated processing
[Go]四、模块和包、流程控制、结构体
Anaconda\Scripts\pip-script.py is not present ? 解决方案
Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
ENVI Image Processing (6): NDVI and Vegetation Index
SyntaxError: EOL while scanning string literal
SQL 改写系列七:谓词移动
【ROS进阶篇】第十一讲 基于Gazebo和Rviz的机器人联合仿真(运动控制与传感器)
Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
机器学习——特征选择
[ARC092D] Two Faced Edges
简单理解精确率(Precision),召回率(Recall),准确率(Accuracy),TP,TN,FP,FN
无代码开发平台应用可见权限设置入门教程
shell 编程规范与变量
【23考研】408代码题参考模板——链表