# 2022蓝桥杯C/C++ A组个人题解

#include<bits/stdc++.h>
using namespace std;
int main(){
int n=20,m=22;
cout<<4+min(m,n)-1+(max(m,n)-1)*min(m,n);
}

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> nums(n+1,0);、
vector<int> sum(n+1,0);
for(int i =1;i<=n;i++){
cin>>nums[i];
sum[i]=sum[i-1]+nums[i];
}
long long ans=0;
for(int i = 1;i<n;i++ ){
ans+=nums[i]*(sum[n]-sum[i]);
}
cout<<ans;
return 0;
}

$$a\oplus b=x$$可以得到$$a \oplus x=b$$

#include<bits/stdc++.h>

using namespace std;

int main() {
int n, m, x;
cin >> n >> m >> x;
vector<int> nums(n, 0);
map<int, vector<int>> mp;
for (int i = 0; i < n; i++) {
cin >> nums[i];
mp[nums[i]].push_back(i + 1);
}
int l, r;
for (int i = 0; i < m; i++) {
cin >> l >> r;
bool ans=false;
for (int j = l - 1; j < r - 1; j++) {
if (mp.count(nums[j] ^ x) > 0) {
vector<int> idx = mp[nums[j] ^ x];
int count = 0;
for (int k = 0; k < idx.size(); k++) {
if (idx[k]>=l&&idx[k]<=r){
count++;
}
if(nums[j]^x!=nums[j]&&count>=1){
ans=true;
}
if(nums[j]^x==nums[j]&&count>=2){
ans=true;
}
}
if(ans){
break;
}
}
}
if(ans){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}

return 0;
}

dp+模拟