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, ...
随机推荐
- Spring MVC 到 Spring Boot 的简化之路(山东数漫江湖)
背景 从Servlet技术到Spring和Spring MVC,开发Web应用变得越来越简捷.但是Spring和Spring MVC的众多配置有时却让人望而却步,相信有过Spring MVC开发经验的 ...
- 【HMOI】小C的填数游戏 DP+线段树维护
[题目描述] 一个长为n的序列,每个元素有一个a[i],b[i],a[i]为0||1,每个点和他相邻的两个点分别有两条边,权值为cost1[i],cost2[i],对于每个区间l,r,我们可以给每一个 ...
- 关于Linux下s、t、i、a权限
文件权限除了r.w.x外还有s.t.i.a权限: 首先我们利用umask查看系统的权限为四位,首位就是特殊权限位,SetUID为4,SetGID为2,t为1 [root@iz2ze46xi6pjjj6 ...
- yocto 离线编译
使用yocto编译一个软件包时,一般会先在本地寻找下载好的源码包,如果不存在则根据配置从网络下载. 添加本地源码包 为了支持离线编译,添加一个包的配置文件后,需要在本地也准备好源码包. 可以先打开网络 ...
- linux系统下git使用
转载:http://www.cnblogs.com/bear2flymoon/p/4335364.html?ADUIN=563508762&ADSESSION=1430887070&A ...
- Python基础=== Tkinter Grid布局管理器详解
本文转自:https://www.cnblogs.com/ruo-li-suo-yi/p/7425307.html @ 箬笠蓑衣 Grid(网格)布局管理器会将控件放置到一个二维的表 ...
- gnu app url[web][5星]
http://www.gnu.org/software/software.zh-cn.html http://linux.chinaunix.net/news/2010/12/07/1175310.s ...
- Bookmarks www
Bookmarks alexis- (Alex Incogito) - Repositories · GitHub GitHub - aetcnc-Arduino_DeltaHMI_RS485 Ope ...
- 手机meta标签(保存下来省的每次都找)
手机网站Meta标签 手机端特有的Meta标签 1.<meta name="viewport" id="viewport" content="w ...
- MAC Pro 2017款 无线上网慢
MAC Pro 2017款 在无线路由器和MAC相隔一个房间,上网很慢,怀疑是无线路由器有问题,但其他几台老款MAC和PC上网正常.后来将蓝牙关掉,上网就很快了.