CF1322B-Present【双指针】
正题
题目链接:https://www.luogu.com.cn/problem/CF1322B
题目大意
给出\(n\)个数字\(a_i\)求
\]
\(1\leq n\leq 4\times 10^5,1\leq a_i\leq 10^7\)
解题思路
分位考虑的话,先把每个位置更高位的给去掉,此时两个数字和这位为\(1\)的情况当且仅当他们的和在\([2^k,2^{k+1})\)或者\([2^{k+1}+2^k,2^{k+2})\)这两个区间。
双指针扫两次就好了。
时间复杂度\(O(n\log a_i)\)
code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=4e5+10;
ll n,a[N],b[N],sum;
signed main()
{
scanf("%lld",&n);
for(ll i=1;i<=n;i++)
scanf("%lld",&b[i]);
for(ll k=0;k<25;k++){
ll l=1,r=0,ans=0;
for(ll i=1;i<=n;i++)
a[i]=b[i]&((1ll<<k+1)-1);
sort(a+1,a+1+n);
for(ll i=n;i>=1;i--){
ll L=(1ll<<k)-a[i],R=(1ll<<k+1)-a[i];
while(r<n&&a[r+1]<R)r++;
while(l<=n&&a[l]<L)l++;
if(l>=i)break;
ans+=min(r,i-1)-l+1;
}
l=1,r=0;
for(ll i=n;i>=1;i--){
ll L=(1ll<<k+1)+(1ll<<k)-a[i],R=(1ll<<k+2)-a[i];
while(r<n&&a[r+1]<R)r++;
while(l<=n&&a[l]<L)l++;
if(l>=i)break;
ans+=min(r,i-1)-l+1;
}
sum+=(ans&1)*(1ll<<k);
}
printf("%lld\n",sum);
return 0;
}
CF1322B-Present【双指针】的更多相关文章
- X000100
P3172 [CQOI2015]选数 gcd 为 \(K\) 不太好办,所以我们先把它转化成 gcd 为 1 的问题: scanf("%d%d%d%d",&n,&k ...
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)
D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...
- 跳转时候提示Attempt to present on while a presentation is in progress
出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...
- find your present (感叹一下位运算的神奇)
find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HTTP Status 400 - Required String parameter 'userName' is not present 错误
HTTP Status 400 - Required String parameter 'userName' is not present 错误 先mark 有时间详细写 参考链接: https:/ ...
- Linux 克隆虚拟机引起的“Device eth0 does not seem to be present, delaying initialization”
虚拟机Vmware上克隆了一个Red Hat Enterprise Linx启动时发现找不到网卡,如下所示,如果你在命令窗口启动网络服务就会遇到"Device eth0 does not s ...
- required string parameter XXX is not present
@RequestParam jQuery调用方式: deleteFile: function(filePath) { return ajax({ method: 'POST', url: '/cm/s ...
- 启动网卡报:Device eth0 does not seem to be present”解决办法
Device eth0 does not seem to be present”解决办法 : 用ifconfig查看发现缺少eth0,只有lo:用ifconfig -a查看发现多出了eth1的信息. ...
- jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque
问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present ...
随机推荐
- 微信小程序全局数据globalData的使用问题
如果在A页面设置全局属性,但在B页面无法使用的话,可能是这个问题: app.js globalData: { helpPage:0, }, A页面 A(e) { getApp().globalData ...
- MongoDB使用命令创建用户权错误分析--- 权限不够Error:couldn't add user:command createUser requires authentication
MongoDB使用命令创建用户权错误分析 错误一:权限不够Error:couldn't add user:command createUser requires authentication. 解决方 ...
- C#硬件访问(摄像头、麦克风)
#需要引用:AForge类库.Microsoft.DirectX using System;using System.Windows.Forms;namespace CameraTest{ publi ...
- 【springcloud】springcloud Greenwich SR4版本笔记
springcloud Greenwich SR4版本笔记 本文只记录实际版本,配置,pom,代码以及注意事项.别的在其他springcloud 的F版本中已有详述. 示例代码地址:https://g ...
- springboot&&springcloud知识点
spring cloud 常见面试题: A.https://blog.csdn.net/panhaigang123/article/details/79587612 B.https://blog.cs ...
- 关于Ubuntu18.04 linux系统使用搜狗输入法 出现乱码
解决: 执行下面的命令即可!无需重启系统 killall fcitx
- (强制)要求覆写equals必须覆写hashCode(原理分析)
hashCode和equals hashCode和equals用来标识对象,两个方法协同工作可用来判断两个对象是否相等.众所周知,根据生成的哈希将数据散列开来,可以使存取元素更快.对象通过调用Obje ...
- MySQL锁(表锁,行锁,共享锁,排它锁,间隙锁)使用详解
锁,在现实生活中是为我们想要隐藏于外界所使用的一种工具.在计算机中,是协调多个进程或县城并发访问某一资源的一种机制.在数据库当中,除了传统的计算资源(CPU.RAM.I/O等等)的争用之外,数据也是一 ...
- Ansible部署及配置介绍
原文转自:https://www.cnblogs.com/itzgr/p/10233932.html作者:木二 目录 一 Ansible的安装部署 1.1 PIP方式 1.2 YUM方式 二 Ansi ...
- 安全强化机制——SELinux
1.基本 SELINUX 安全性概念 SELINUX(Security Enhanced Linux),意思是安全增强型Linux, 是可保护你系统安全性的额外机制 在某种程度上 , 它可以被看作是与 ...