0w1

CF 579D "Or" Game ( Ad hoc )

Problem - D - Codeforces
We should notice that it is necessary to somehow maximize the largest number, so all the x should be multiplied on the same number, otherwise the most significant digit could be pushed even further. However we cannot simply take the maximum number, for there is possibility that some smaller number will have the same number of digits in binary expressions but with better second significant digit. We will have to check for each number in the array and choose the maximum. We could achieve this quickly by preprocessing the prefix and suffix OR of the initial array.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int MAXK = 10;
const int MAXX = 8;

int n, k, x;
ll a[MAXN];
ll pre[MAXN], suf[MAXN];

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> k >> x;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i)
        pre[i] = pre[i - 1] | a[i];
    for(int i = n; i >= 1; --i)
        suf[i] = suf[i + 1] | a[i];
    ll mul = 1LL; while( k-- ) mul *= x;
    ll ans = 0LL;
    for(int i = 1; i <= n; ++i)
        ans = max<ll>( ans, pre[i - 1] | ( a[i] * mul ) | suf[i + 1] );
    cout << ans << endl;
    return 0;
}