Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心
B. "Or" Game
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/578/problem/B
Description
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make as large as possible, where
denotes the bitwise OR.
Find the maximum possible value of after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 ≤ n ≤ 200 000, 1 ≤ k ≤ 10, 2 ≤ x ≤ 8).
The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Sample Input
3 1 2
1 1 1
Sample Output
3
HINT
题意
给你n个数,你可以操作k次,使得其中的某一个数乘以x
要求最后得到的所有数的或值最大
题解:
首先dp是错的,因为a>b不能保证a|c>b|c
这儿有一个贪心的操作,如果又一次乘法给了a1,那么剩下的都得给a1,这样才能得到最优值
因为x>=2可以保证最高位的1在不断增加
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000000 + 500
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
//**************************************************************************************
long long n , k , x; struct tree
{
int L , R ;
ll sum;
}; tree a[maxn * ];
ll d[maxn];
void build(int x,int l,int r)
{
a[x].L = l,a[x].R = r;
if(l == r)
{
a[x].sum = d[l];
return;
}
else
{
int mid = (l+r)>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
a[x].sum = a[x<<].sum | a[x<<|].sum;
}
} ll query(int o,int QL,int QR)
{
int L = a[o].L , R = a[o].R;
if (QL <= L && R <= QR) return a[o].sum;
else
{
int mid = (L+R)>>;
ll res = ;
if (QL <= mid) res |= query(*o,QL,QR);
if (QR > mid) res |= query(*o+,QL,QR);
return res;
}
}
int main()
{
cin>>n>>k>>x; for(int i = ; i <= n ; ++ i)
{
scanf("%I64d",&d[i]);
}
build( , , n+);
ll ans = ;
ll temp = ;
for(int i=;i<=k;i++)
temp *= x;
for(int i = ; i <= n ; ++ i)
{
ans = max( ans , (d[i]*temp) | query(,,i-) | query(,i+,n+));
}
cout<<ans<<endl;
}
Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心的更多相关文章
- Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树
https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum 离线+线段树
题目链接: http://codeforces.com/contest/703/problem/D D. Mishka and Interesting sum time limit per test ...
- Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树
B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...
- Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树
D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp
C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game
题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分
E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】
A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 数学+(前缀 后缀 预处理)
D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 转载:C++ map的基本操作和使用
声明:本文转自:http://www.cnblogs.com/hailexuexi/archive/2012/04/10/2440209.html 1.map简介 map是一类关联式容器.它的特点是增 ...
- poj3321Apple Tree(树状数组)
http://poj.org/problem?id=3321 刚一看题以为要建一颗树 看了下讨论说dfs 这里dfs遍历时设的标号很好 一个low一个high 包含了以这一节点为根节点的子树结点的所有 ...
- 结构体buf_page_t
/** Buffer page (uncompressed or compressed) */ typedef struct buf_page_struct buf_page_t; struct bu ...
- web旋转式
为了获取客户.回馈客户,平台一般会推出抽奖活动类的营销页.因此web页面中,有各式各样的抽奖效果. 格子式(九宫格),背景滚动式(数字/文字/图案),旋转式(转盘),游戏式(砸蛋/拼图...).... ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.6
Let $A$ be a nilpotent operator. Show how to obtain, from aJordan basis for $A$, aJordan basis of $\ ...
- bug描述注意点
一个好的错误跟踪系统包括了错误的必要信息,如果做得不好,会造成迷惑,并误导读者.好的故障描述应该包括十个基本部分:标题.项目.所属模块.优先级.重要性.异常等级.可重复性.现象.操作过程和附件. ①标 ...
- 解读四大移动web应用开发框架真相
[51CTO译文]近来关于新的移动网页框架及移动平台存在不少争论.平心而论,这些工具在条款内容方面的混乱与模糊也是造成大家误解的原因之一.我希望通过几条简短的评述来尽量清理这种认识层面上的混乱状态. ...
- Linux shell 获取当前时间之前N天
date +%Y%m%d --date '2 days ago' 更多资料关注:www.kootest.com ;技术交流群:182526995
- mysql远程连接出现 ERROR 2003 (HY000): Can't connect to MySQL server on IP
修改了如下两个位置,解决了这个问题: 修改/etc/mysql/my.cof配置文件:因为mysql默认只允许本机连接 修改远程连接用户权限:远程连接的用户被设置为不允许远程连接 首先修改/etc/m ...
- C# 检测机器是否有声卡设备
有时候我们的程序需要进行音频的播放,则我们首先需要判断机器是否有声卡能够进行音频的播放.在网上找了一下没有发现太多关于如何检机器是否有声卡的例子.我在看了一些文档后自己写了一个小测试程序,如果机器装有 ...