文章
68
粉丝
691
获赞
26
访问
578.4k
只有90分,求大佬答疑
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
using namespace std;
#define ll long long
#define vec vector<int>
#define inf 0x3f3f3f3f
#define MAX 500005
#define P pair<ll,ll>
#define MOD 1000000007
int main() {
int n, a[MAX], sum[MAX];
while (cin >> n) {
sum[0] = 0;
map<int, vec> m; m[0].push_back(0);
for (int i = 0; i < n; i++)
{
cin >> a[i];
sum[i + 1] = sum[i] ^ a[i];
m[sum[i + 1]].push_back(i + 1);
}
int res = 0;
int des = 0;
for (map<int, vec>::iterator k = m.begin(); k != m.end(); k++) {
vec t = (*k).second;
if (t.size() <= 1)continue;
for (int i = 0; i < t.size(); i++)
for (int j = i + 1; j < t.size(); j++)
if ((t[j] - t[i]) % 2 == 0)
res++;
}
cout << ...
登录后发布评论
题目数据范围不大,空间换时间可以继续优化