4245: [Ontak2015]or-xor

Source: Internet
Author: User

4245: [Ontak2015]or-xor

https://www.lydsy.com/JudgeOnline/problem.php?id=4245

1 /*2 The requirements are divided into m parts, the total value is a1|a2|a3 ..., the total value is minimal, AI is the XOR of the first part. 3  4 The first preprocessing is XOR. 5 According to the greedy thought, the high position is preferably 0. 6 so from high to low enumeration, see if each bit can be 0. 7 if the current bit can be 0, each copy (XOR) (or) is 0, so each share of the XOR or the bit cannot have 18 then a point can become a split point when and only if this bit of the sum value of the point is 0, then count how many points the sum is 09 If the number is >=m and all 1 on this one is an even number (sum[n]& (1ll<<i) ==0), then this bit can be 0, and then for those points that cannot be split, the marker can no longer become a split point. Ten Otherwise it would make this person not 0.  One if not 0, that would be 1, ans update.  A */ -#include <bits/stdc++.h> - using namespacestd; thetypedefLong LongLL; -   - inline LL Read () { -LL x=0, f=1;CharCh=getchar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; +      for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0';returnx*F; - } +   A Const intN =500100; at LL A[n],sum[n],flag[n]; -   - intMain () { -     intN,m;cin >> N >>m; -      for(intI=1; i<=n; ++i) -A[i] = Read (), sum[i] = sum[i-1] ^A[i]; inLL ans =0;  -      for(intI= +; i>=0; -I.) {//See if I can be 0 for the first place . to         intCNT =0; +          for(intj=1; j<=n; ++J) {//count how many right endpoints meet the criteria -             if(!flag[j] && (sum[j]& (1ll<<i)) = =0) cnt++; the         } *         if(CNT >= m && (sum[n]& (1ll<<i)) = =0) {//If this person can put 0. ----Less on curly braces ...  $              for(intj=1; j<=n; ++J)//Mark All points that cannot be the right endpointPanax Notoginseng                 if((sum[j]& (1ll<<i))! =0) Flag[j] =1; -         } the         ElseAns |= (1LL <<i); +     } Acout <<ans; the     return 0; +}

4245: [Ontak2015]or-xor

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.