Codeforces Round #320 (Div. 2) "or" Game (good question, greedy/bitwise operation/prefix suffix or)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.