-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcumulative-update-array.cpp
52 lines (48 loc) · 1015 Bytes
/
cumulative-update-array.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
/*siddharth goyal*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define REP(i, n) for (i = 1; i <= n; i++)
#define FOR(i, a, b) for (i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define vl vector<LL>
#define itr ::iterator it
#define lb lower_bound
#define ub upper_bound
#define LL long long
#define ULL unsigned long long
#define ret return
LL n, i, j, ans = 0;
LL a[10000000];
void f(LL x) {
ans += (x * (x - 1)) / 2;
}
int main() { // Read the constraints,highlights,Time Limit,Test Cases
freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
REP(i, n) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
for (i = 1; i <= n; i++) cout << a[i] << " ";
cout << endl;
LL x = 0;
for (i = 1; i <= n; i++) {
LL k = 0, l = 0;
for (j = i + 1; j <= n; j++) {
k = max(k, a[j] - a[j - 1]);
if (k == 1)
l++;
if (k > 1)
break;
}
if (l)
f(j - i);
i = j - 1;
}
cout << ans << endl;
}