# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1249976 | s4dz | Triple Peaks (IOI25_triples) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
/*
Author: s4dz
*/
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll maxn = 1000005;
const ll inf = 1e9 + 7;
int n, arr[maxn], q, a, b, c;
int st[4 * maxn], lazy[4 * maxn];
std::vector<int> construct_range(int M, int K)
{
}
long long count_triples(std::vector<int> H)
{
ll ans = 0;
for(int k = 1; k <= n; k++)
{
int i = k - H[k];
int j1 = i + H[i];
int j2 = k - H[i];
int temp = H[i];
int hj = max(H[i], H[k] - H[i]);
if(i < j1 && j1 < k && H[j1] == hj) ans++;
if(j1 != j2 && j2 > i && j2 < k && H[j2] == hj) ans++;
}
return ans;
}
int main()
{
cin >> n;
vector<int> H(n + 1);
for(int i = 1; i <= n; i++) cin >> H[i];
cout << count_triples(H);
}