社区讨论
求助, 92分 #4 TLE
P1102A-B 数对参与者 3已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lzjcay37
- 此快照首次捕获于
- 2024/08/07 12:19 2 年前
- 此快照最后确认于
- 2024/08/07 14:01 2 年前
CPP
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
long long int n, c, m[200005], ans[2][200005] = { 0 }, s = 0, ch;
long long int x = 0;
long long int f(int a)
{
long long int k = c + ans[0][a];
for (int i = ch; i < s; i++)
{
if (ans[0][i] == k)
{
ch = i;
return ans[1][i] * ans[1][a];
}
}
return 0;
}
int main()
{
cin >> n >> c;
for (int i = 0; i < n; i++)
{
scanf("%lld", &m[i]);
}
sort(m, n + m);
ans[0][0] = m[0];
ans[1][0] = 1;
for (int i = 1; i < n; i++)
{
if (m[i] == m[i - 1])
{
ans[1][s]++;
}
else
{
ans[0][++s] = m[i];
ans[1][s] = 1;
}
}
s++;
ch = 0;
for (int i = 0; i < s; i++)
{
x += f(i);
}
cout << x;
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...