传送门

文章目录

  • 题意:
  • 思路:

题意:

给你一个长度为nnn的序列aaa,让你计算

n≤4e5,a≤1e7n\le 4e5,a\le 1e7n≤4e5,a≤1e7

思路:

首先这个式子是n2n^2n2的,显然不能直接算,并且异或没有分配律,所以碰到这种情况我们自然的就想到按位考虑。
分开考虑每一位,假设当前为第kkk位,当这一位是111的时候,两个数的和一定在[2k,2k+1−1][2^k,2^{k+1}-1][2k,2k+1−1]之间,由于有可能会溢出,比如全是111的情况相加,所以还有可能在[2k+2k+1,2k+2−2][2^k+2^{k+1},2^{k+2}-2][2k+2k+1,2k+2−2]之间,我们可以取出来每个数模上2k+12^{k+1}2k+1之后的数,将他们排个序,之后双指针扫一遍,注意要倒着扫才能保证正确性,算一下有多少对在这一位有贡献的,让后看奇偶性就好啦。
直接做的复杂度显然是nlognloganlognloganlognloga,这个题显然是能过去的,但是我们可以再优化一下它。
考虑到枚举每一位是不能优化掉的,我们对排序进行优化。
观察可以知道我们每次都只考虑某一位之前的数,并且每次都增加一位,所以我们每次只执行一次快排,因为对于新增加的一位我们能将其分成两部分,这一位如果是111就放在右边,否则放在左边,让后双指针扫一下就可以排出序来了。
复杂度nloganloganloga。

// Problem: D. Present
// Contest: Codeforces - Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)
// URL: https://codeforces.com/contest/1323/problem/D
// Memory Limit: 512 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
int a[N],b[N];
int ans=0;
int L[N],R[N],Lid[N],Rid[N],id[N];int get(int L,int R) {if(L>R) return 0;int ans=0;for(int i=n,l=1,r=1;i>=1;i--) {while(l<=n&&b[l]+b[i]<L) l++;while(r<=n&&b[r]+b[i]<=R) r++;ans+=r-l-(l<=i&&i<r);}return ans>>1&1;
}void merge(int k) {int l,r; l=r=0;for(int i=1;i<=n;i++) {if(a[id[i]]>>k&1) R[++r]=b[i]|(1<<k),Rid[r]=id[i];else L[++l]=b[i],Lid[l]=id[i];}int p1=1,p2=1,p=1;while(p1<=l&&p2<=r) {if(L[p1]<=R[p2]) b[p]=L[p1],id[p++]=Lid[p1++];else b[p]=R[p2],id[p++]=Rid[p2++];}while(p1<=l) b[p]=L[p1],id[p++]=Lid[p1++];while(p2<=r) b[p]=R[p2],id[p++]=Rid[p2++];
}int calc(int x) {merge(x);return (get(1<<x,(1<<(x+1))-1)+get(3<<x,(1<<(x+2))-2))%2;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]),id[i]=i;for(int i=0;i<25;i++) ans+=calc(i)<<i;printf("%d\n",ans);return 0;
}
/**/

Codeforces Round #626 (Div. 2) D. Present 按位贡献 + 快排新姿势相关推荐

  1. Codeforces Round #262 (Div. 2) 460C. Present

    题目连接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  2. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  3. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)C. Unusual Competitions

    C. Unusual Competitions time limit per test1 second memory limit per test512 megabytes inputstandard ...

  4. Codeforces Round #626 (Div. 2)

    A 这个似乎出过一遍了?选一个偶数或者两个奇数. B 题意: 给你nnn个数a1,a2,a3,a4......ana_1,a_2,a_3,a_4......a_na1​,a2​,a3​,a4​.... ...

  5. Codeforces Round #626(Div.2) 解题报告

    Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) [前言] 最近沉迷只狼,好久没有打CF了,水平 ...

  6. Codeforces Round #706 (Div. 2)-B. Max and Mex-题解

    目录 Codeforces Round #706 (Div. 2)-B. Max and Mex Problem Description Input Output Sample Input Sampl ...

  7. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  8. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  9. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

最新文章

  1. firefox ie table 布局 兼容性问题
  2. 优化你的DiscuzNT3.0,让它跑起来(4)asp.net 缓存和死锁
  3. 【剑指offer】面试题10- II:青蛙跳台阶问题(Java)
  4. pyspark对应的scala代码PythonRDD对象
  5. DataGear 1.13.1 发布,数据可视化分析平台
  6. 进位位判别法_''进位-判断-执行''的通用思想
  7. 方正小标宋简体 官方标准版
  8. mysql uroot pg t_【原创】MySQL和PostgreSQL 导入数据对比
  9. 蒋烁淼云计算创业十二年:从云厂商的影子到打造中国版Datadog
  10. 中央广播电视大学中等专业办公设备使用与维护
  11. 一个破解压缩包密码的软件——ziperello
  12. 洛谷B2095 白细胞计数(sort排序)
  13. ERD Online 4.0.3_fix 元数据在线建模(免费、私有部署)
  14. 应用统计学与R语言实现学习笔记(五)——参数估计
  15. oracle 索引的创建和生效
  16. hive中开窗函数 :percent_rank()的含义
  17. 计算机组策略怎么设置远程桌面,组策略 之   自动启用客户端远程桌面功能
  18. Java小程序制作——单词翻译器,原来可以这么简单
  19. 设计师如何在整理设计规范中变强
  20. 网页中用PHP设计一个计算器,用PHP写一个计算器(附完整代码)_后端开发

热门文章

  1. excel中调用python程序_一篇文章带你使用Python搞定对Excel表的读写和处理
  2. 为什么程序员发现不了自己的BUG?
  3. 服务器 不支持gbk,解决JS请求服务器gbk文件乱码的问题
  4. 会计电算化的重要物质基础计算机和,湖北工业大学工程技术学院会计电算化管理办法...
  5. docker源码_使用docker、Jenkins、gitlee、springboot、搭建个人博客网站 并实现CI/CD 外加机器人提醒...
  6. python根据地址查看变量名_tensorflow创建变量以及根据名称查找变量
  7. android canvas_Android 如何实现气泡选择动画
  8. php server 连接字符串,sqlServer 数据库常用连接字符串
  9. 超详细图解!【MySQL进阶篇】SQL优化-索引-存储引擎
  10. 被问到了!为什么一定要使用分布式,内行啊