跳到正文

题解

题解:P12177 [蓝桥杯 2025 省 Python B] 异或和

Lihangyi123约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年7月30日
收录
2025年12月12日
更新
2026年11月19日
篇幅
约 1 分钟
获赞
1
题目
P12177

版本

  1. v1当前

因为是python题,所以时间有5秒。我们可以利用__int128暴力过。 代码如下:

C++
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define ll long long
using namespace std;
const int N=1e5+5;
int n,a[N];
__int128 ans,p=1e18;
signed main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n){
		rep(j,i+1,n){
			ans+=1ll*(a[i]^a[j])*(j-i);
		}
	}
	ll x=ans/p,y=ans%p;
	if(x)printf("%lld%018lld",x,y);
	else printf("%lld\n",y);
	return 0;
}
原文