Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonTang89 authored May 20, 2024
1 parent 8885c1b commit 032b69d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions Other_Tasks/CF1974_C_Beautiful_Triple_Pairs.cpp
Original file line number Diff line number Diff line change
@@ -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 <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
vector<int> a;
map<pair<int, int>, int> mp[3];
map<tuple<int, int, int>, 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;
}

0 comments on commit 032b69d

Please sign in to comment.