cf1058e thinking prefix processing

Source: Internet
Author: User

The question is: given a length of(n≤3x105) of the seriesai (1≤< Span id= "mathjax-span-21" class= "Msubsup" >a i≤ 1018) Exchange a number of arbitrary bits, ask how many intervals you can select after Operation XOR 0

Links: Http://codeforces.com/contest/1058/problem/E

Idea: Because of the binary exchange at will, then its own value does not have to consider, just want to save it has how many binary 1 of the number is good.

Sufficient and necessary conditions:

    • The number of binary 1 in the interval is even
    • The number of bits in the interval is less than or equal to half of the number of the binary

For condition One

So the parity of (L,R) is judged by the parity of (0,l), so that the parity of all the prefixes is counted, and the degree of responsibility of O (n) is calculated.

For the time being, add all the conditions and subtract from the condition two.

Because AI <1e18 the >1 limit, enumerating about 60 bits can be as

#include <bits/stdc++.h>using namespacestd;#definell Long Long#definePB Push_back#defineFi first#defineSe Second#defineAll (v) v.begin (), V.end ()#defineForn (i,a,n) for (int i=a;i<n;++i)Const intN = 3e5+4; ll A[n],b[n];ll Cbit (ll x) {ll res=1;  while(x) {if(x&1) res++; X/=2; }    returnres-1;} ll Sum[n];intcnt[2];intMain () {intN; CIN>>N; Forn (i,1, n+1) {scanf ("%lld", A +i); B[i]=cbit (A[i]); } ll ans=0 ; cnt[0]=1; //1 (1..j-1), J is even//here 's a formula to illustrateForn (I,1, n+1) {Sum[i]= sum[i-1]+B[i]; Ans+ = cnt[sum[i]&1];//1 (0..J), J is even//here 's a formula to illustrate//In accordance with condition 2, minus the past.        intJ =i,k=i; ll Max=B[i];  while(k>=1&& j-k<= +) {Max=Max (max,b[k]); if(max*2> sum[i]-sum[k-1] && ((sum[i]-sum[k-1] )%2==0)) ans--; K--; } Cnt[sum[i]&1]++; //cout<<ans<<endl;} cout<<ans<<Endl; return 0;}

---restore content ends---

 

cf1058e thinking prefix processing

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.