# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1250049 | s4dz | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
std::vector<int> construct_range(int M, int K)
{
return{};
}
long long count_triples(const vector<int>& H)
{
int n = H.size();
ll ans = 0;
for (int k = 0; k < n; k++)
{
int c = H[k];
int i = k - c;
if (i < 0 || i >= n) continue;
int a = H[i];
if (a > c - a) continue;
int need = c - a;
int j1 = i + a;
int j2 = k - a;
if (i < j1 && j1 < k && H[j1] == need) ans++;
if (j2 != j1 && i < j2 && j2 < k && H[j2] == need) ans++;
}
return ans;
}