#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//sub4:
vector<int> construct_range(int M, int K)
{
long long n = M;
vector<int> ans1 =
{
4, 3, 1, 2, 1,
4, 3, 2, 7, 6,
5, 8, 11, 10, 9,
1, 7, 2, 3, 4,
};
if(M <= 20)
{
while(ans1.size() > n || ans1.back() >= n) ans1.pop_back();
return ans1;
}
vector<int> a = {1,2,1};
long long tmp = 2;
while(a.size() < n)
{
long long v = a.size() + 1;
for(int i = 0; i < tmp + 1; i++) a.push_back(v-i);
tmp = v;
}
while(a.size() > n || a.back() >= n) a.pop_back();
return a;
}
/*long long count_triples(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;
}*/
long long count_triples(vector <signed> H)
{
int n = H.size();
long long ans = 0;
//Hj = j - i
for(int j = 0; j < n; j++)
{
for(int i = max(0, j - H[j] + 1); i < j && i + H[j] < n; i++)
{
int k = i + H[j];
int x = H[k], y = H[i];
int d1 = j - i, d2 = k - j;
if((H[k] == d1 && H[i] == d2) || (H[k] == d2 && H[i] == d1)) ans++;
}
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) ans++;
if(y != x && H[l + y] == y) ans++;
}
}
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) ans++;
if(y != x && H[j + y] == y) ans++;
}
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |