1. 程式人生 > >Wannafly挑戰賽1 B Xorto

Wannafly挑戰賽1 B Xorto

時間 subject question type top -c spa 異或和 組元

Xorto 時間限制:2秒 空間限制:32768K

題目描述

給定一個長度為n的整數數組,問有多少對互不重疊的非空區間,使得兩個區間內的數的異或和為0。

輸入描述:

第一行一個數n表示數組長度;
第二行n個整數表示數組;
1<=n<=1000,0<=數組元素<100000。

輸出描述:

一行一個整數表示答案。
示例1

輸入

3
0 0 0

輸出

5

說明

([1,1],[2,2]),([1,1],[3,3]),([1,1],[2,3]),([1,2],[3,3]),([2,2],[3,3])
 1 #include<bits/stdc++.h>
 2 using
namespace std; 3 typedef long long ll; 4 const int N=10004; 5 6 int a[N],b[N*200]; 7 8 int main(){ 9 int n; 10 cin>>n; 11 for(int i=1;i<=n;i++){ 12 int x; 13 scanf("%d",&x); 14 a[i]=a[i-1]^x; 15 } 16 ll sum=0; 17 for(int i=1;i<=n;i++){
18 for(int j=i;j<=n;j++){ 19 sum+=b[a[j]^a[i-1]]; 20 } 21 for(int j=i;j>=1;j--) 22 b[a[i]^a[j-1]]++; 23 } 24 cout<<sum<<endl; 25 }

Wannafly挑戰賽1 B Xorto