C. Count Triangles
显然两边之和大于第三边
我们可以先预处理出来这个两边之和
我们暴力枚举x 然后区间赋值[x+b,x+c]+1
然后最后暴力枚举第三个边 然后将大于第三边的方案数加上就是了
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int s[N];
void solve(){
int a,b,c,d;cin>>a>>b>>c>>d;
for(int x=a;x<=b;x++){
s[x+b]++,s[x+c+1]--;
}
for(int i=0;i<=1e6;i++)s[i]+=s[i-1];
for(int i=0;i<=1e6;i++)s[i]+=s[i-1];
int ans=0;
for(int z=c;z<=d;z++){
ans+=s[N-10]-s[z];
}
cout<<ans<<endl;
}
signed main(){
fast
int t;t=1;//cin>>t;
while(t--) {
solve();
}
return ~~(0^_^0);
}
标签:const,int,Codeforces,long,643,return,Div,998244353
From: https://www.cnblogs.com/ycllz/p/16833524.html