From 032b69d3cb8fa405e38e68f2a5ab7a85375f0ea6 Mon Sep 17 00:00:00 2001 From: Brandon Tang <43487872+BrandonTang89@users.noreply.github.com> Date: Mon, 20 May 2024 20:58:58 +0100 Subject: [PATCH] Add files via upload --- .../CF1974_C_Beautiful_Triple_Pairs.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Other_Tasks/CF1974_C_Beautiful_Triple_Pairs.cpp diff --git a/Other_Tasks/CF1974_C_Beautiful_Triple_Pairs.cpp b/Other_Tasks/CF1974_C_Beautiful_Triple_Pairs.cpp new file mode 100644 index 0000000..fa0091d --- /dev/null +++ b/Other_Tasks/CF1974_C_Beautiful_Triple_Pairs.cpp @@ -0,0 +1,57 @@ +/**CF1974C + * Straightforward but annoying implementation problem. It is important to remember that the triples are + * ordered. + */ +#pragma GCC optimize("Ofast") +#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") +#pragma GCC optimize("unroll-loops") +#include +using namespace std; + +typedef long long ll; + +int n; +vector a; +map, int> mp[3]; +map, int> trips; + +int main() +{ + int tc; + cin >> tc; + while (tc--) { + cin >> n; + a.resize(n); + for (int i = 0; i < n; i++) { + cin >> a[i]; + } + + mp[0].clear(); + mp[1].clear(); + mp[2].clear(); + trips.clear(); + + ll ans = 0; + for (int i = 0; i < n - 2; i++) { + // consider the triple a[i], a[i+1], a[i+2] + int x = a[i]; + int y = a[i + 1]; + int z = a[i + 2]; + ll cur = -3LL * trips[{x, y, z}]; + trips[{x, y, z}]++; + + cur += (ll)mp[0][{x, y}]; + mp[0][{x, y}]++; + cur += (ll)mp[1][{y, z}]; + mp[1][{y, z}]++; + cur += (ll)mp[2][{z, x}]; + mp[2][{z, x}]++; + + ans += cur; + } + + cout << ans << endl; + } + + return 0; +} \ No newline at end of file