1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <iostream>5 using namespacestd;6typedefLong Longll;7 /*8 n number, you have a maximum of k operations, each operation can choose a number multiplied by x, ask all the numbers or (|) The maximum value9 greedy idea: Choose a number to do k this times x operation; because x>=2Ten 111---> 1111 One 111---> 1111 A Better - 111---> 11111; - 111---> 111; the The idea of prefixes and suffixes is used: - */ -ll pre[200005]; Pre[i] is a[1]|a[2].....| A[i]; -ll suf[200005]; +ll a[200005]; - ll ans; + intMain () { A at intn,k,x; - while(SCANF ("%d%d%d", &n,&k,&x)! =EOF) { - for(inti =1; I <= N; i + +) scanf ("%i64d",&a[i]); - for(inti =1; I <= N; i + +) pre[i] = pre[i-1]|A[i]; - for(inti = n; I >=1; I--) suf[i] = suf[i+1]|A[i]; -ll num =1; in for(inti =1; I <= K; i + +) num *=x; - for(inti =1; I <= N; i + +) ans = max (ans,pre[i-1]|a[i]*num|suf[i+1]); toprintf"%i64d\n", ans); + } - the * return 0; $}
Codeforces Round #320 (Div. 2) "or" Game (good question, greedy/bitwise operation/prefix suffix or)