码迷,mamicode.com
首页 > 其他好文 > 详细

Wannafly挑战赛1 B Xorto

时间:2017-10-14 15:13:51      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:输入   scan   describe   mina   color   style   question   异或   ons   

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

标签:输入   scan   describe   mina   color   style   question   异或   ons   

原文地址:http://www.cnblogs.com/hhxj/p/7666910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!