-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path086-count-triangles.cpp
More file actions
53 lines (52 loc) · 1.22 KB
/
Copy path086-count-triangles.cpp
File metadata and controls
53 lines (52 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Count Triangles [1355C]
* Problem: https://codeforces.com/problemset/problem/1355/C
* Verdict: ACCEPTED Solved: 2022-06-29
* Language: C++20 (GCC 11-64)
* Runtime: 15 ms Memory: 0 KB
* Tags: binary search, implementation, math, two pointers
* Author: BidoTeima
* Source: https://codeforces.com/contest/1355/submission/162284162
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ACPLS()
{
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc int tttt;cin>>tttt;while(tttt--)
ll summation(ll l, ll r){
if(l>r)
return 0;
return r*(r+1)/2 - l*(l-1)/2;
}
ll calc(ll c, ll x, ll y){
if(y>=c)
return summation(c-min(c,x)+1,c+1);
ll d = c-y;
ll ret = (y+1)*min(d+1,x+1);
x-=min(d,x);
return ret+summation(max(0ll,y-x+1), y);
}
int main()
{
ACPLS();
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll ans=0;
for(ll x = a; x <= b; x++){
ans+=calc(x-1,c-b,d-c);
}
cout<<ans;
}