蓝桥杯 2022 A组C题
简单

#include<bits/stdc++.h>
using namespace std;
const int maxn = 200001;
int a[maxn];
long long sum[maxn];
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
long long total = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
total += a[i];
}
sum[0] = total;
for (int i = 1; i <= n; i++)
{
sum[i] = sum[i - 1] - a[i - 1];
}
long long ans = 0;
for (int i = 0; i < n; i++)
ans += a[i] * sum[i + 1];
cout << ans;
}
中等


#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 10;
int yihuo[maxn];
map<long long, int>num_index;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
long long x;
cin >> n >> m >> x;
for (int i = 1; i <= n; i++)
{
long long t;
cin >> t;
yihuo[i] = max(yihuo[i - 1], num_index[t ^ x]);
num_index[t] = i;
}
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
if (yihuo[b] >= a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
划重点
- 加速
ios_base::sync_with_stdio(false);
cin.tie(0);
- 加速
#define endl "\n"
-
a^b=c,则a^c=b