Topic links
Once again I see the bit operation must be the first time I want to split it into every
The subject is a prefix and sum[], and then let you ask each of the number of I,j meet sum[i]-sum[j] on that one is 1
Consider how you can reduce the
If sum[i] in this bit is 1, then need J is 0 and Sum[i] front of the number is less than sum[j] before the number, so as not a decrease in the bit, the sum[i] this bit of 1 minus
If it's 0.
Consider maintaining with a weighted tree array.
#include <cstdio>#include<algorithm>#include<cstring>#include<cctype>#include<cstdlib>#defineMAXN 1000010using namespaceStd;inlineLong LongRead () {Long Longnum=0, f=1; CharCh=GetChar (); while(!isdigit (CH)) { if(ch=='-') f=-1; CH=GetChar (); } while(IsDigit (CH)) {num=num*Ten+ch-'0'; CH=GetChar (); } returnnum*F;} InlineintLowintx) {returnx& (-x); }inttot;intSUM[MAXN];structtree{intTREE[MAXN]; voidClear () {memset (tree,0,sizeof(tree)); } InlinevoidAddintPOS) { while(pos<=tot) {Tree[pos]++; POS+=Low (POS); }} inlineintAskintPOS) { intans=0; while(pos>0) {ans+=Tree[pos]; POS-=Low (POS); } returnans; }}zero,one;intMain () {intn=read (); for(intI=1; i<=n;++i) sum[i]=sum[i-1]+read (); Tot=sum[n]+1; intans=0; for(intI=0;(1<<i) <=tot;++i) {zero.clear (); One.clear (); intCnt=0; Zero.add (1); for(intj=1; j<=n;++j) { intNow= (sum[j]% (1<<i)) +1; if((sum[j]>>i) &1)==1) {CNT+=Zero.ask (now); CNT+=one.ask (TOT)-One.ask (now); One.add (now); } Else{cnt+=zero.ask (TOT)-Zero.ask (now); CNT+=One.ask (now); Zero.add (now); } } //printf ("%d%d\n", i,cnt); if(cnt&1) ans+=1<<i; } printf ("%d", ans); return 0;}
"Luogu" P3760 xor (Weighted tree-like array)