这个数据范围,\(n是1e6,a_i也是1e6\),任意\(a_i+a_j \in [0, 2e6]\),所以如果有答案我们最多枚举\(2e6\)个数就可以找到答案
void solve()
{
int n;
cin >> n;
vector<int> a(n);
map<int, int> mp;
for (int i = 0; i < n;i ++)
cin >> a[i];
for (int i = 0; i < n;i ++)
{
for (int j = i + 1; j < n;j ++)
{
mp[a[i] + a[j]]++;
if(mp[a[i] + a[j]] == 2)
{
cout << "YES\n";
return;
}
}
}
cout << "NO\n";
}
标签:int,四川大学,2e6,1e6,++,2023,mp,鸽巢
From: https://www.cnblogs.com/cxy8/p/17876956.html