[CC-XXOR]Chef and Easy Problem
[CC-XXOR]Chef and Easy Problem
题目大意:
给你一个长度为\(n(n\le10^5)\)的序列\(A(A_i<2^{31})\)。\(m(m\le10^5)\)次询问,每次给定一个区间\([l,r]\),求使得\(\sum_{i=l}^r(A_i\oplus x)\)最大的\(x(x<2^{31})\)是多少。
思路:
按位考虑,如果这一位是\(1\)的数比较多那么就把\(x\)的这一位弄成\(0\),否则弄成\(1\)。
源代码:
#include<cstdio>
#include<cctype>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
const int N=1e5+1,B=31;
int a[N];
int sum[N][B];
int main() {
const int n=getint(),q=getint();
for(register int i=1;i<=n;i++) {
const int x=getint();
for(register int j=0;j<B;j++) {
sum[i][j]=sum[i-1][j];
if((x>>j)&1) sum[i][j]++;
}
}
for(register int i=0;i<q;i++) {
const int l=getint(),r=getint(),len=r-l+1;
int x=0;
for(register int i=0;i<B;i++) {
if((sum[r][i]-sum[l-1][i])*2<len) x|=1<<i;
}
printf("%d\n",x);
}
return 0;
}
[CC-XXOR]Chef and Easy Problem的更多相关文章
- POJ 2826 An Easy Problem?![线段]
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12970 Accepted: 199 ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- POJ 2826 An Easy Problem?!
An Easy Problem?! Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7837 Accepted: 1145 ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?
UVa11991 Easy Problem from Rujia Liu? 思路: 构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- UVA 11991 Easy Problem from Rujia Liu?(vector map)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
随机推荐
- Apache POI - Excel
基于模板的EXCEL报表组件ExcelUtils:http://blog.csdn.net/hanqunfeng/article/details/4834875 http://blog.csdn.ne ...
- Bellman-Ford 最短路径算法
算法证明:http://courses.csail.mit.edu/6.006/spring11/lectures/lec15.pdf 先来看一个这样的图: 这是含有负边权的,如果是用djistra的 ...
- 【整理】Git相关资料
http://book.51cto.com/art/201107/278731.htm http://book.51cto.com/art/201107/278828.htm
- systemd的电源管理
ArchLinux早就使用systemd替代了init脚本. 不用图形界面.或者使用 i3.awesome 这样简单的窗口管理器时,systemd 可以替代 acpid 处理 ACPI 事件. 注意: ...
- FinalShell 推荐
FinalShell是一体化的的服务器,网络管理软件,不仅是ssh客户端,还是功能强大的开发,运维工具,充分满足开发,运维需求. 用户QQ群 342045988 Windows版下载地址:http:/ ...
- objective-c 几何类常用方法整理
CGGeometry参考定义几何结构和功能,操作简单.数据结构中的一个点CGPoint代表在一个二维坐标系统.数据结构的位置和尺寸CGRect代表的一个长方形.数据结构的尺寸CGSize代表宽度和高度 ...
- golang container heap&sort
go语言也自己的容器数据结构.主要有list.heap和ring package main import ( "container/heap" "fmt" &q ...
- 【C++】cmdline——轻量级的C++命令行解析库
1.说明 cmdline是一个轻量级的c++命令行参数解析工具,全部源码只有一个cmdline.h头文件. 2.代码 20171210_命令行进行解析.cpp // 20171210_命令行进行解析. ...
- iptables-25个常用用法【转】
本文介绍25个常用的iptables用法.如果你对iptables还不甚了解,可以参考上一篇iptables详细教程:基础.架构.清空规则.追加规则.应用实例,看完这篇文章,你就能明白iptables ...
- C# UDP广播消息
首先是发送端: /// <summary> /// 发送UDP消息 /// </summary> /// <param name="msg">消 ...