题解
考虑以下决策
\(x+y\in S\) \(\to\) \(y=-x+S_i\)
\(y-x\in S\) \(\to\) \(y=x+S_i\)
答案为红线上点的数量加上蓝线上点的数量减去交叉点(整数)的数量
由于 \(S_i<=c\)
所以 交叉点等价于画斜率等于 \(-1\) 的斜线时与起点同号的斜率为 \(1\) 的交叉点个数,为什么是同号?因为这样的交叉点才为整数
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll s[300005]={0};
int main()
{
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll n,c;
cin>>n>>c;
ll sum=(c+1+1)*(c+1)/2;
for(ll i=1;i<=n;i++)
{
cin>>s[i];
sum-=s[i]/2+1;
sum-=c-s[i]+1;
}
ll even=0,odd=0;
for(ll i=1;i<=n;i++)
{
even+=1-s[i]%2;
odd+=s[i]%2;
if(s[i]%2) sum+=odd;
else sum+=even;
}
cout<<sum<<endl;
}
return 0;
}
标签:Exam,sum,cin,long,MAC,交叉点,ll
From: https://www.cnblogs.com/pure4knowledge/p/18075560