# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1251382 | tranvinhhuy2010 | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include "triples.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nmax = 2e5 + 5;
int n;
unordered_map <int, set <int>> mk;
ll count_triples(vector <int> H) {
n = H.size();
ll cnt = 0;
for (int j=0; j<n; j++) {
int l = j - H[j];
if(l >= 0)
{
int x = H[l];
int y = H[j] - x;
if(y > 0)
{
if(H[l + x] == y) cnt++;
if(y != x && H[l + y] == y) cnt++;
}
}
int r = j + H[j];
if(r < n)
{
int x = H[r];
int y = H[j] - x;
if(y > 0)
{
if(H[j + x] == y) cnt++;
if(y != x && H[j + y] == y) cnt++;
}
}
mk[j - H[j]].insert(i);
}
for (int i=0; i<n; i++) {
mk[i - H[i]].erase(i);
for (int k : mk[i + H[i]]) {
int j = i + H[k];
if (j<k && H[j]==k-i) cnt++;
}
}
return cnt;
}
vector<int> construct_range(int M, int K) {
return {1, 1, 1};
}