[BZOJ4888] [TJOI2017] xor (tree-like array)

Source: Internet
Author: User
Tags ming

Title Description

Xiao Ming in Garidon Middle school recently fell in love with the maths contest, and many maths competitions are sequential and related to the sequence. So for a sequence, find out all of their continuous and, xiaoming feel very simple. But today Xiao Ming encountered a sequence and the problem, this topic not only requires you to quickly find out all the continuous and, but also to quickly find out these successive and different values. Xiaoming soon to find out all the continuous and, but Xiao Ming to test you, in not telling the continuous and the case, let you quickly be realistic sequence all consecutive and the XOR value.

Input/output format

Input format:

The first line enters an n, which indicates that the sequence of numbers in the second row of input n number a1,a2...an represents this sequence

0<=A1,A2,... an,0<=a1+a2...+an<=10^6

Output format:

Outputs all successive and XOR values of this sequence.

Input and Output sample input sample #: Copy

31 2 3
Output Example # #: Replication
0
Description

"Sample Interpretation"

Sequence 1 2 3 has 6 consecutive and they are 1 2 3 3 5 6, then 1 XOR 2 XOR 3 XOR 3 XOR 5 xor 6 = 0

"Data Range"

For 20% of data, 1<=n<=100

For 100% of data, 1<=n <= 10^5

Interval and conversion to prefix and the difference, the tree-like array of the discussion can be.

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineRep (i,l,r) for (int i=l; i<=r; i++)5 using namespacestd;6 7 Const intn=100100, m=1000000;8 intflag,cnt,c[m+5][2],s[n],a[n],ans;9 intpw[ +],n;Ten  One voidAddintXintY) { while(x<=m) c[x][y]++,x+= (x& (-x)); } A intQueryintXinty) { -    intsum=0; while(x) sum+=c[x][y],x-= (x& (-x)); -    returnsum; the } -  - intMain () { -scanf"%d",&n); +Rep (I,1, N) scanf ("%d", &s[i]), s[i]+=s[i-1]; -pw[0]=1; Rep (I,1, -) pw[i]=pw[i-1]*2; +Rep (I,0, -) A       if(pw[i]<=S[n]) { atMemset (c,0,sizeof(c)); -flag=0; Add1,0); -Rep (J,1, N) { -             inttmp=s[j]&Pw[i]; -             if(TMP) Cnt=query (a[j]+1,0) +query (1000001,1)-query (a[j]+1,1); -             ElseCnt=query (a[j]+1,1) +query (1000001,0)-query (a[j]+1,0); in             if(cnt%2==1) flag^=1; -Add (a[j]+1,(BOOL) tmp); to             if(TMP) a[j]|=Pw[i]; +          } -          if(flag) ans|=(Pw[i]); the       } *printf"%d\n", ans); $    return 0;Panax Notoginseng}

[BZOJ4888] [TJOI2017] xor (tree-like array)

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.