正题

题目链接:https://www.luogu.com.cn/problem/CF1322B


题目大意

给出\(n\)个数字\(a_i\)求

\[\bigoplus _{i=1}^n\bigoplus _{j=i+1}^n(a_i+a_j)
\]

\(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【双指针】的更多相关文章

  1. X000100

    P3172 [CQOI2015]选数 gcd 为 \(K\) 不太好办,所以我们先把它转化成 gcd 为 1 的问题: scanf("%d%d%d%d",&n,&k ...

  2. 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 ...

  3. 跳转时候提示Attempt to present on while a presentation is in progress

    出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...

  4. find your present (感叹一下位运算的神奇)

    find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. HTTP Status 400 - Required String parameter 'userName' is not present 错误

    HTTP Status 400 - Required String parameter 'userName' is not present 错误 先mark  有时间详细写 参考链接: https:/ ...

  6. Linux 克隆虚拟机引起的“Device eth0 does not seem to be present, delaying initialization”

    虚拟机Vmware上克隆了一个Red Hat Enterprise Linx启动时发现找不到网卡,如下所示,如果你在命令窗口启动网络服务就会遇到"Device eth0 does not s ...

  7. required string parameter XXX is not present

    @RequestParam jQuery调用方式: deleteFile: function(filePath) { return ajax({ method: 'POST', url: '/cm/s ...

  8. 启动网卡报:Device eth0 does not seem to be present”解决办法

    Device eth0 does not seem to be present”解决办法 : 用ifconfig查看发现缺少eth0,只有lo:用ifconfig -a查看发现多出了eth1的信息. ...

  9. 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 ...

随机推荐

  1. Jpa-操作mongodb

    pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spr ...

  2. npm 基本命令的使用

    1.npm -v 查看npm版本 2.使用npm命令安装模块 npm install Module Name 例如安装jquery模块 npm install jquery 3.卸载模块 npm un ...

  3. [转]用C++实现插件体系结构

    本文讨论一种简单却有效的插件体系结构,它使用C++,动态链接库,基于面向对象编程的思想.首先来看一下使用插件机制能给我们带来哪些方面的好处,从而在适当时候合理的选择使用. 1. 增强代码的透明度与一致 ...

  4. 【C#】GC和析构函数(Finalize 方法)

    析构函数: (来自百度百科)析构函数(destructor) 与构造函数相反,当对象脱离其作用域时(例如对象所在的函数已调用完毕),系统自动执行析构函数.析构函数往往用来做"清理善后&quo ...

  5. udphdr结构

    udphdr结构包含在/usr/src/linux/include/linux/udp.h 1 struct udphdr { 2 __u16 source; 3 __u16 dest; 4 __u1 ...

  6. Java中的比较器(排序)

    "顺序"在任何一个领域里都是非常重要的一个概念,程序也不例外.不同的执行顺序,能对你的执行结果产生直接影响. 既然涉及到顺序,那就要求排序.所以本文讨论的就是排序中使用到的比较器C ...

  7. yum 和 epel 的详解

    一.概览 1.什么是repo文件 repo文件是Fedora中yum源(软件仓库)的配置文件,通常一个repo文件定义了一个或者多个软件仓库的细节内容,例如我们将从哪里下载需要安装或者升级的软件包,r ...

  8. Longhorn 云原生容器分布式存储 - Air Gap 安装

    内容来源于官方 Longhorn 1.1.2 英文技术手册. 系列 Longhorn 是什么? Longhorn 云原生容器分布式存储 - 设计架构和概念 Longhorn 云原生容器分布式存储 - ...

  9. Spring Data JPA:解析CriteriaQuery

    CriteriaQuery 源码定义 CriteriaQuery定义在包路径javax.persistence.criteria下,其定义如下: /** * The <code>Crite ...

  10. java发送短信开发,第三方接口方法

    必备的三个jar包Maven有自己去下: commons-logging commons-logging 1.1 commons-httpclient commons-httpclient 3.1 c ...