Bzoj 4017 Sub-sequences and XOR and XOR and

Source: Internet
Author: User

A good bit of a property is that each individual can be considered ....

Please see: http://blog.csdn.net/skywalkert/article/details/45401245

For XOR and, first enumerate bits, ask for all XOR and sum, and the number of the bits in 1, multiplied by the size of that bit (2 of how many times squared).

That is, each individual consideration, each with a different right.

For the xor of the and, just know each bit and change the parity of 1, you can know the final XOR value on the bit is 0 or 1.

Also consider each person individually, looking at the condition of 0 or 1.

1 /**************************************************************2 problem:40173 user:idy0024 language:c++5 result:accepted6 time:9896 Ms7 memory:3544 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cstring> A#include <algorithm> - #defineN 100010 - #defineMod 998244353 the using namespacestd; -   -typedefLong Longdnt; -   + intN; - intAa[n]; +   A namespaceTask1 { at dnt ans; -     intcnt[2]; -Dnt Mpow (Dnt A,intb) { - dnt RT; -          for(rt=1; b b>>=1, a=a*a%Mod) -             if(b&1) Rt=rt*a%Mod; in         returnRT; -     } to     voidMain () { +          for(intb=0; b<= -; b++ ) { -cnt[0] = cnt[1] =0; the              for(intI=1; i<=n; i++ ) { *                 intbb = (aa[i]>>b) &1; $                 intC0 = cnt[0];Panax Notoginseng                 intC1 = cnt[1]; -cnt[0^BB] =C0; thecnt[1^BB] =C1; +cnt[bb]++; AAns = (ans+cnt[1]*mpow (2, b))%Mod; the             } +         } -printf"%lld", ans); $     } $ }; - namespaceTask2 { - dnt s[n]; the dnt disc[n], Dtot; -     intbit[2][n];Wuyi dnt ans; the     voidinit () { -memset (bit,0,sizeof(bit)); Wu     } -     voidModifyintBit[],intAintDelta) {//a in [1,n] About          for(intI=a; i<=dtot; i+=i&-i) $Bit[i] + =Delta; -     } -     intQueryintBit[],inta) { -         intRT =0; A          for(intI=a; I i-=i&-i) +RT + =Bit[i]; the         returnRT; -     } $     voidMain () { the          for(intI=1; i<=n; i++ )  theS[i] = s[i-1] +Aa[i]; the          for(intb=0; b<= *; b++ ) { theDnt cnt =0; -Dnt mask = (1ll<<b)-1; inDtot =0; theDisc[++dtot] =0; the              for(intI=1; i<=n; i++ ) AboutDisc[++dtot] = S[i] &Mask; theSort (disc+1, disc+1+Dtot); theDtot = Unique (disc+1, disc+1+dtot)-Disc-1; the init (); +Modify (bit[0], Lower_bound (disc+1, disc+1+dtot,0)-disc, +1 ); -              for(intI=1; i<=n; i++ ) { theDnt bmid = (s[i]>>b) &1;BayiDnt brgt = s[i] &Mask; the                 intIRGT = Lower_bound (disc+1, disc+1+dtot, BRGT)-disc; the                 if(bmid) { -CNT + = query (bit[0], IRGT); -CNT + = query (bit[1], Dtot)-Query (bit[1], IRGT); the}Else { theCNT + = query (bit[0], Dtot)-Query (bit[0], IRGT); theCNT + = query (bit[1], IRGT); the                 } -Modify (Bit[bmid], IRGT, +1 ); the             } theAns |= (cnt&1) ? (1LL&LT;&LT;B):0; the         }94printf"%lld\n", ans); the     } the }; the  98 intMain () { Aboutscanf"%d", &n); -      for(intI=1; i<=n; i++ ) 101scanf"%d", aa+i);102 Task1::main ();103 Task2::main ();104 } the 
View Code

Bzoj 4017 Sub-sequences and XOR and XOR and

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.