[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的更多相关文章

  1. POJ 2826 An Easy Problem?![线段]

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12970   Accepted: 199 ...

  2. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  3. An easy problem

    An easy problem Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  4. 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, ...

  5. POJ 2826 An Easy Problem?!

    An Easy Problem?! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7837   Accepted: 1145 ...

  6. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  7. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  8. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

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

随机推荐

  1. bzoj千题计划216:bzoj1499: [NOI2005]瑰丽华尔兹

    http://www.lydsy.com/JudgeOnline/problem.php?id=1499 预处理从每个位置向每个方向最多能走几步 dp[k][i][j] 第k个时间段后,钢琴到位置(i ...

  2. 高斯—若尔当(约当)消元法解异或方程组+bitset优化模板

    高斯消元法是将矩阵化为上三角矩阵 高斯—若尔当消元法是 选定主元后,将主元化为1,枚举除主元之外的所有行进行消元 即将矩阵化为对角矩阵,这样不用回代 bitset<N>a[N]; int ...

  3. 那些年的 网络通信之 UDP 数据报包传输---

    下面是 一个多线程,基于 UDP 用户数据报包 协议 的 控制台聊天小程序 import java.io.*; import java.net.*; class Send implements Run ...

  4. JMS学习(五)--ActiveMQ中的消息的持久化和非持久化 以及 持久订阅者 和 非持久订阅者之间的区别与联系

    一,消息的持久化和非持久化 ①DeliveryMode 这是传输模式.ActiveMQ支持两种传输模式:持久传输和非持久传输(persistent and non-persistent deliver ...

  5. Eclipse的个性化设置

    Eclipse的个性化设置 1. 在Eclipse中查看JDK源码的配置 a. 点 “window”-> "Preferences" -> "Java&quo ...

  6. CodeForces 1059B

    Description Student Andrey has been skipping physical education lessons for the whole term, and now ...

  7. E - 食物链

    题目链接:https://cn.vjudge.net/contest/66964#problem/E 关系式: ra->rb=(ra->b + b->rb )%3; ra->b ...

  8. mybatis动态sql——(六)

    0     什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 通过mybatis提供的各种标签方法实现动态拼接sql.

  9. os_mudule_docs

    pydoc os Help on module os: NAME os - OS routines for Mac, NT, or Posix depending on what system we' ...

  10. Linux中断(interrupt)子系统之一:中断系统基本原理【转】

    转自:http://blog.csdn.net/droidphone/article/details/7445825 这个中断系列文章主要针对移动设备中的Linux进行讨论,文中的例子基本都是基于AR ...