-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLove Triangle.cpp
More file actions
74 lines (59 loc) · 1.15 KB
/
Love Triangle.cpp
File metadata and controls
74 lines (59 loc) · 1.15 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "bits/stdc++.h"
#ifdef LOCAL
#include "F:\CPP\Debug\debug.h"
#else
#define print(...) 1;
#endif
using i64 = long long;
void solve()
{
int n;
std::cin >> n;
std::map<int, int> p, s;
std::vector<int> a(n);
for (int i = 0; i < n; i++)
{
std::cin >> a[i];
s[a[i]]++;
}
if (n <= 2)
{
std::cout << "0\n";
return;
}
auto get = [&](auto & m, int l, int r)
{
i64 ans = 0;
for (int i = l; i <= r; i++)
ans += m[i];
return ans;
};
s[a[0]]--;
i64 ans = 0;
for (int i = 1; i < n - 1; i++)
{
p[a[i - 1]]++;
s[a[i]]--;
int y = a[i];
for (int x = y - 2; x <= y + 2; x++)
{
for (int z = y - 2; z <= y + 2; z++)
{
if (std::max({x, y, z}) - std::min({x, y, z}) >= 3)
continue;
ans += 1LL * p[x] * s[z];
}
}
}
std::cout << ans << "\n";
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--)
solve();
return 0;
}