CF1931D 题解
思路
题目中说要让
进一步转换,可以得到
因为加号两边都肯定小于
同理可得
我们可以使用 STL 中的 map<pair<int, int>, int> 来维护。
设当前枚举的
要特判如果
Code
typedef long long LL;
typedef pair<int, int> PII;
void work()
{
map<PII, int> cnt;
cnt[{a[1] % x, a[1] % y}] = 1;
LL ans = 0;
for (int i=2;i<=n;i++)
{
int A = x - a[i] % x;
if (a[i] % x == 0)
A = 0;
ans += cnt[{A, a[i] % y}];
cnt[{a[i] % x, a[i] % y}] ++;
}
}