社区讨论
为什么用unordered_multiset会TLE?
P3799小 Y 拼木棒参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @lodhuaa9
- 此快照首次捕获于
- 2023/10/31 06:50 2 年前
- 此快照最后确认于
- 2023/11/06 22:05 2 年前
CPP
#include <iostream>
#include <unordered_set>
using namespace std;
unordered_multiset<int> S;
inline int C2(int x)
{
return x * (x - 1) / 2;
}
int main()
{
cin.sync_with_stdio(false);
int n, a, M = 0;
cin >> n;
while (n--)
cin >> a, S.insert(a), M = max(M, a);
long long ans = 0;
for (int i = 1; i < M; i++)
{
for (int j = i; j <= M - i; j++)
if (i != j)
ans += S.count(i) * S.count(j) * C2(S.count(i + j));
else
ans += C2(S.count(i)) * C2(S.count(i * 2));
ans %= 1000000007;
}
cout << ans << flush;
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...