-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
84 lines (78 loc) · 2.35 KB
/
C.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/// by ahmed_drawy 15/03/20
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std;
#define ll long long
#define inN(arr , n) for(int i = 0 ; i< n ; ++i) cin>>arr[i];
#define lp(i,start , end) for(int i = start ; i<end ; ++i)
#define sz(v) (int)((v).size())
#define clr(v,d) memset(v , d , sizeof(v));
#define pii pair<int, int>
#define vii vector<ll>
#define vi vector<int>
#define endl '\n'
#define debug(x) cerr << x<<endl;
const double EPS = (1e-7);
void smile() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/tw3/Desktop/Desktop/training/in.txt", "r", stdin);
// freopen("/home/tw3/Desktop/Desktop/training/out.txt" , "w" , stdout);
#endif
}
int dcmp(double x, double y) { return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1; }
int randomF() {
return (rand() * RAND_MAX + rand()) % 1000000;
}
ll MOD =(ll) 1e9 +7 ;
int mod(ll x){
return (x%MOD + MOD)%MOD;
}
long long add(long long x, long long y){
x += y;
while(x >= MOD)
x -= MOD;
while(x < 0)
x += MOD;
return x;
}
ll multipy(ll x , ll y ){
return ((x%MOD) *(y%MOD))%MOD;
}
long long power(long long base, int exp){
if (!exp)
return 1LL;
ll sq = power(base, exp/2);
sq = (sq * sq)%MOD;
if (exp&1)
sq = (sq * base)%MOD;
return sq;
}
bool compareT(pair<int , int > & a , pair<int ,int > &b){
if(a.first != b.first)
return a.first <b.first ;
return a.second< b.second ;
}
double dist(int x , int y , int a , int b) {
return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
int main() {
smile();
int n , d ; cin >> n >> d;
vi arr(n);
for (int i = 0; i <n ; ++i) {
cin >> arr[i];
}
ll ans = 0 ;
for (int i = 0; i < n; ++i) {
int u = upper_bound(arr.begin() , arr.end() , arr[i] + d) - arr.begin() -1;
/// we need u - i C 2 --> k*(k-1)/2
ll k = u- i ;
ans +=(k*(k-1))/2;
}
cout << ans << endl;
}