D. "Or" Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note

For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is .

For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result

题意:给你一个长度为n的序列 可以执行k次操作  每次操作可以将序列中的任意一个数乘以x

使得最后的连续OR(|运算)的值最大

题解:为了使得最后的值很大 应该将增益集中在某一位上 使得高位不断左移

但是应该增加在哪一位上呢?并不是一定增加在现有序列的最大值上  有hack数据

3 1 2

4 5 6

所以直接暴力枚举 寻找最大值  但是需要先预处理前缀或 后缀或 具体看代码

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll __int64
using namespace std;
ll n,k,x;
ll a[];
ll exm;
ll gg;
ll ans1[];
ll ans2[];
ll ma;
int main()
{
ma=;
scanf("%I64d %I64d %I64d ",&n,&k,&x);
for(ll i=;i<=n;i++)
scanf("%I64d",&a[i]);
exm=;
for(ll i=;i<=k;i++)
exm*=x;
ll s=;
ans1[]=;
for(ll i=;i<=n;i++)//前缀
{
s=(s|a[i]);
ans1[i]=s;
}
s=;
ans2[n+]=;
for(ll i=n;i>=;i--)//后缀
{
s=(s|a[i]);
ans2[i]=s;
}
for(ll i=;i<=n;i++)
ma=max(ma,ans1[i-]|(a[i]*exm)|ans2[i+]);
cout<<ma<<endl;
return ;
}

Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 数学+(前缀 后缀 预处理)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game

    题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...

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

  5. 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 ...

  6. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E 三分+连续子序列的和的绝对值的最大值

    E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)

    显然f(x)是个凹函数,三分即可,计算方案的时候dp一下.eps取大了会挂精度,指定循环次数才是正解. #include<bits/stdc++.h> using namespace st ...

  8. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)

    首先应该保证二进制最高位尽量高,而位数最高的数乘x以后位数任然是最高的,所以一定一个数是连续k次乘x. 当出现多个最高位的相同的数就枚举一下,先预处理一下前缀后缀即可. #include<bit ...

  9. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)

    题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的 ...

随机推荐

  1. 操作系统(1)_操作系统结构_李善平ppt

    cpu和内存之间通过地址总线.数据总线.控制总线连接.外部总线连接外部设备.下图有问题,内存和外设没有直接连接.同一组总线,CPU和内存连接的时候硬盘就不能和内存连接,否则有冲突,core和core之 ...

  2. JSPatch - iOS 动态补丁

    JSPatch库,支持在线更新iOS应用,目前BDN项目中有用到,主要用来修复线上Crash和Bug 相关博文推荐: JSPatch – 动态更新iOS APP(这是JSPatch作者的博文) JSP ...

  3. 更改zabbix-server的端口

    1.前言zabbix-server的默认端口号是10051.如果存在端口号冲突,需要更改端口号. 以下为更改端口号的步骤. 2.更改配置文件 通常用安装包,也就是yum方式部署的话,其默认的配置文件是 ...

  4. 成员变量(实例变量)&局部变量&静态变量(类变量)的区别

    成员变量(实例变量)&局部变量区别: (1)作用域 成员变量:针对整个类有效. 局部变量:只在某个范围内有效.(一般指的就是方法,语句体内) (2)存储位置 成员变量:随着对象的创建而存在,随 ...

  5. nuxt.js服务端缓存lru-cache

    对于部分网页进行服务端的缓存,可以获得更好的渲染性能,但是缓存又涉及到一个数据的及时性的问题,所以在及时性和性能之间要有平衡和取舍. 官方文档里面写的使用方法 按照这个配置,试过了没什么用,但是从文档 ...

  6. JZOJ 4421. aplusb

    4421. aplusb Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits   Goto ProblemSet Descr ...

  7. 【转载】MQTT的学习之Mosquitto集群搭建

    本文出自:http://www.cnblogs.com/yinyi521/p/6087215.html 文章钢要: 1.进行双服务器搭建 2.进行多服务器搭建 一.Mosquitto的分布式集群部署 ...

  8. Linux 面试的一些基础命令

    1.查询服务器负载 (1)uptime [root@oldboy ~]# uptime 20:17:18 up 7:41, 2 users, load average: 0.00, 0.00, 0.0 ...

  9. Disharmony Trees HDU - 3015

    Disharmony Trees HDU - 3015 One day Sophia finds a very big square. There are n trees in the square. ...

  10. shell脚本中的交互式输入自动化

    shell中有时我们需要交互,但是呢我们又不想每次从stdin输入,想让其自动化,这时我们就要使shell交互输入自动化了. 1    利用重定向     重定向的方法应该是最简单的 例: 以下的te ...