bzoj 4017: 小Q的无敌异或
4017: 小Q的无敌异或
Time Limit: 20 Sec Memory Limit: 128 MB
Submit: 593 Solved: 197
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 2
Sample Output
- sum(l−1)mod 2k+1≤(sum(r)mod2k+1)−2k ,0≤sum(l−1)mod2k+1 ,即 0≤sum(l−1)mod2k+1≤(sum(r)mod2k+1)−2k。
- sum(l−1)mod2k+1≤(sum(r)mod2k+1)−2k+2k+1=(sum(r)mod2k+1)+2k ,sum(r)mod2k+1<sum(l−1)mod2k+1 ,即 sum(r)mod2k+1<sum(l−1)mod2k+1≤(sum(r)mod2k+1)+2k 。
我们先离散化所有前缀和的值。在枚举r的过程中,然后看对应区间内的数量是不是奇数个,这个可以用^的树状数组实现。或者权值线段树实现。
这样枚举了右端点后,就能得出ans,若为1则加上相应的2的幂次方作为答案贡献。
#include<bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 998244353
using namespace std;
const int N=1e5+;
int bit[N];
LL a[N];
LL order[N],found[N];
int n,m,k,cnt;
LL ans1,ans2;
void qy1(int mp)
{
LL num=;
LL now=;
for(int i=;i<=n;i++)
{
now^=(a[i]>>mp)&;
if(now)
num++;
}
ans1=(ans1+num*(n-num+)%mod*(1LL<<mp)%mod)%mod;
return ;
}
void add(int i,int x)
{
if(!i) return ;
while(i<=cnt+)
{
bit[i]^=x;
i+= i&-i;
}
return ;
}
int sum(int i)
{
int res=;
while(i)
{
res^=bit[i];
i-= i&-i;
}
return res;
}
void qy2(int mp)
{
clr(bit);
int p;
found[]=order[]=;
for(int i=;i<=n;i++)
{
found[i]=(found[i-]+a[i])%(1LL<<(mp+));
order[i]=found[i];
}
sort(order,order+n+);
cnt=unique(order,order+n+)-order-;
int ans=;
for(int i=;i<=n;i++)
{
p=lower_bound(order,order+cnt+,found[i])-order;
if(order[p]!=found[i]) p--;
p++;
add(p,);
ans^=sum(p);
p=lower_bound(order,order+cnt+,found[i]-(1LL<<mp))-order;
if(order[p]!=found[i]-(1LL<<mp)) p--;
p++;
ans^=sum(p);
p=lower_bound(order,order+cnt+,found[i]+(1LL<<mp))-order;
if(p==cnt+ || order[p]!=found[i]+(1LL<<mp)) p--;
p++;
ans^=sum(p);
}
if(ans) ans2|=(1LL<<mp);
return ;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
ans1=ans2=;
for(int i=;i<=;i++) qy1(i);
for(int i=;i<=;i++) qy2(i);
printf("%lld %lld\n",ans1,ans2);
return ;
}
bzoj 4017: 小Q的无敌异或的更多相关文章
- BZOJ 4017 小 Q 的无敌异或 ( 树状数组、区间异或和、区间异或和之和、按位计贡献思想 )
题目链接 题意 : 中文题 分析 : 首先引入两篇写的很好的题解 题解一.题解二 听说这种和异或相关区间求和的问题都尽量按位考虑 首先第一问.按二进制位计贡献的话.那么对于第 k 位而言 其贡献 = ...
- BZOJ4017 小Q的无敌异或(位运算)
题目链接 小Q的无敌异或 好久之前做的这道题了……参照了别人的博客……还是没有全懂. 第一个问题维护个前缀就好了,第二个问题还要用树状数组维护…… #include <bits/stdc++.h ...
- bzoj 4815 小Q的表格 —— 反演+分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 思路就和这里一样:https://blog.csdn.net/leolyun/arti ...
- BZOJ [Cqoi2017] 小Q的棋盘
题解:枚举最后在哪里停止,然后剩下的步数/2 也就是找最大深度 枚举终止位置算是一种思路吧 #include<iostream> #include<cstdio> #inclu ...
- bzoj 4813: [Cqoi2017]小Q的棋盘
Description 小Q正在设计一种棋类游戏.在小Q设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能 在有连线的格点之间移动.整个棋盘上共有V个格点,编号为0,1,2-,V- ...
- bzoj 4813: [Cqoi2017]小Q的棋盘 [树形背包dp]
4813: [Cqoi2017]小Q的棋盘 题意: 某poj弱化版?树形背包 据说还可以贪心... #include <iostream> #include <cstdio> ...
- bzoj 4815: [Cqoi2017]小Q的表格 [数论]
4815: [Cqoi2017]小Q的表格 题意: 单点修改,查询前缀正方形和.修改后要求满足条件f(a,b)=f(b,a), b×f(a,a+b)=(a+b)*f(a,b) 一开始sb了认为一次只会 ...
- 【BZOJ 5125】小Q的书架
Problem Description 小 \(Q\) 有 \(n\) 本书,每本书有一个独一无二的编号,现在它们正零乱地在地上排成了一排. 小 \(Q\) 希望把这一排书分成恰好 \(k\) 段,使 ...
- 腾讯笔试题:小Q硬币组合
腾讯有一道机试题: 大概意思是: 小Q非常富有,拥有非常多的硬币,小Q的拥有的硬币是有规律的,对于所有的非负整数K,小Q恰好> 各有两个数值为2^k,的硬币,所以小Q拥有的硬币是1,1,2,2, ...
随机推荐
- 表格td内容超出宽度显示... table-layout: fixed;
td宽度用百分比固定好的时候,即使设置了 white-space:nowrap;/*文本不会换行,在同一行显示*/ overflow:hidden;超出隐藏 text-overflow:ellipsi ...
- 使用SQL Server连接xml接口,读取并解析数据
--数据源格式,放到任意程序中部署接口即可--<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmln ...
- Python的异常处理机制 -- (转)
当你的程序中出现异常情况时就需要异常处理.比如当你打开一个不存在的文件时.当你的程序中有一些无效的语句时,Python会提示你有错误存在. 下面是一个拼写错误的例子,print写成了Print.Pyt ...
- A题 hdu 1235 统计同成绩学生人数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1235 统计同成绩学生人数 Time Limit: 2000/1000 MS (Java/Others) ...
- 通过实例来学习XML DTD
使用DTD的原因: 注意:由于它自身的一些缺点,DTD终将被淘汰,但是它还是要学习的.学习完DTD后,后面继续学习XML Schema. 1,通过 DTD,您的每一个 XML 文件均可携带一个有关其自 ...
- ubuntu gnome桌面秀
之前装的是ubuntu14.10gnome版的 然后一路升级成15.04,到今天的15.10 最后发现现在的gnome桌面已经非常适合我的工作了 先放一张图,这是我的桌面 原来使用ubuntu15.0 ...
- 安装FFMpeg CentOS 7
https://linuxadmin.io/install-ffmpeg-on-centos-7/
- Exploring Qualcomm's TrustZone Implementation
转自 http://bits-please.blogspot.com/2015/08 (需要FQ, 狗日的墙) In this blog post, we'll be exploring Qua ...
- centos_7.1.1503_src_4
http://vault.centos.org/7.1.1503/os/Source/SPackages/ libkcompactdisc-4.10.5-3.el7.src.rpm 05-Jul-20 ...
- python string 对齐文本的几个方法
用rjust().ljust()和center()方法对齐文本