#include "triples.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define pb push_back
#define st first
#define nd second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(), a.end()
set<pair<pii, int>> S;
pair<pii, int> sor(int a, int b, int c) {
int x = min({a, b, c});
int z = max({a, b, c});
int y = a + b + c - x - z;
return {{x, y}, z};
}
long long count_triples(std::vector<int> T) {
int n = T.size();
ll ans = 0;
rep(i, n) {
int j = i + T[i];
int k[4];
if (j < n) {
k[0] = i + T[j];
k[1] = i - T[j];
k[2] = j + T[j];
k[3] = j - T[j];
rep(c, 4) {
if (i == j || i == k[c] || j == k[c]) continue;
if (k[c] < 0 || k[c] >= n) continue;
int x = T[i];
int y = T[j];
int z = T[k[c]];
int a = abs(i - j);
int b = abs(i - k[c]);
int d = abs(j - k[c]);
if ((x + y + z) != (2 * max({x, y, z}))) continue;
if (sor(a, b, d) != sor(x, y, z)) continue;
S.insert(sor(i, j, k[c]));
}
}
j = i - T[i];
if (j >= 0) {
k[0] = i + T[j];
k[1] = i - T[j];
k[2] = j + T[j];
k[3] = j - T[j];
rep(c, 4) {
if (i == j || i == k[c] || j == k[c]) continue;
if (k[c] < 0 || k[c] >= n) continue;
int x = T[i];
int y = T[j];
int z = T[k[c]];
int a = abs(i - j);
int b = abs(i - k[c]);
int d = abs(j - k[c]);
if ((x + y + z) != (2 * max({x, y, z}))) continue;
if (sor(a, b, d) != sor(x, y, z)) continue;
S.insert(sor(i, j, k[c]));
}
}
}
ans = (long long) S.size();
// for (auto p: S) {
// cout << p.st.st << " " << p.st.nd << " " << p.nd << '\n';
// }
vector<int> jakie[2 * n + 1];
vector<int> jakie2[2 * n + 1];
int iter[n];
int iter2[n];
rep(i, n) {
int x = T[i] - i + n;
iter[i] = jakie[x].size();
jakie[x].pb(i);
}
for (int i = n - 1; i >= 0; i--) {
int x = T[i] + i;
iter2[i] = jakie2[x].size();
jakie2[x].pb(i);
}
rep(i, n) {
int x = T[i] - i + n;
int y = T[i] + i;
int sz = jakie[x].size();
int sz1 = jakie[y].size();
if (sz <= sz1) {
for (int it = iter[i] - 1; it >= 0; it--) {
int j = jakie[x][it];
int k = i + T[j];
if (k < n && ((T[k] + T[j]) == T[i])) {
if (T[k] == T[j]) continue;
ans++;
}
}
}
else {
for (int it = iter2[i] - 1; it >= 0; it--) {
int k = jakie2[y][it];
int j = i - T[k];
if (j >= 0 && ((T[k] + T[j]) == T[i])) {
if (T[k] == T[j]) continue;
ans++;
}
}
}
}
return ans;
}
std::vector<int> construct_range(int M, int K) {
srand(8831);
vector<int> pom = {5, 2, 3, 3, 1, 2, 1, 4, 3, 2, 7, 6, 5, 6, 3, 4, 1, 2, 1, 3};
vector<int> pom2 = {41, 8, 29, 38, 5, 46, 13, 34, 43, 10, 51, 38, 39, 48, 5, 16, 287, 44, 13, 46, 21, 28, 29, 18, 25, 26, 61, 34, 23, 36, 31, 72, 33, 28, 15, 16, 5, 28, 65, 66, 21, 10, 23, 44, 71, 4, 5, 58, 17, 76, 1, 10, 53, 12, 49, 6, 5, 8, 7, 28, 41, 42, 43, 2, 23, 5, 47, 36, 37, 18, 35, 6, 31, 32, 13, 70, 11, 26, 27, 114, 115, 32, 21, 22, 19, 20, 25, 38, 57, 24, 25, 102, 103, 52, 101, 30, 97, 98, 47, 94, 95, 92, 93, 42, 1, 40, 87, 88, 5, 6, 5, 34, 81, 82, 11, 10, 29, 76, 77, 160, 5, 72, 71, 72, 21, 20, 153, 66, 67, 64, 65, 172, 143, 160, 161, 10, 143, 138, 165, 140, 53, 54, 133, 150, 135, 5, 147, 148, 45, 44, 45, 152, 143, 122, 149, 124, 137, 138, 117, 34, 119, 142, 189, 132, 115, 114, 207, 136, 127, 24, 109, 122, 131, 122, 215, 176, 203, 126, 117, 114, 115, 94, 121, 96, 119, 166, 187, 82, 157, 190, 85, 160, 87, 152, 1, 108, 155, 148, 95, 96, 95, 150, 171, 100, 99, 174, 145, 166, 143, 84, 169, 162, 161, 194, 165, 164, 129, 156, 37, 154, 159, 26, 157, 218, 79, 164, 31, 124, 123, 178, 143, 38, 259, 146, 41, 40, 43, 42, 135, 134, 251, 138, 137, 50, 51, 246, 195, 142, 55, 54, 241, 190, 127, 188, 109, 236, 151, 132, 259, 114, 70, 230, 117, 254, 177, 75, 225, 122, 249, 76, 221, 220, 79, 78, 243, 5, 215, 2, 213, 238, 23, 12, 13, 90, 233, 10, 93, 8, 16, 228, 117, 226, 97, 148, 1, 5, 106, 194, 193, 4, 107, 106, 215, 188, 47, 51, 34, 38, 183, 37, 207, 206, 33, 38, 42, 36, 126, 124, 173, 26, 25, 196, 29, 28, 49, 21, 47, 24, 74, 50, 26, 186, 57, 40, 39, 81, 43, 42, 35, 85, 4, 38, 149, 148, 72, 155, 43, 75, 3, 95, 57, 56, 98, 49, 249, 162, 161, 85, 86, 14, 56, 89, 11, 59, 60, 14, 94, 74, 73, 97, 19, 31, 69, 69, 70, 116, 3, 73, 38, 28, 111, 8, 42, 108, 5, 106, 30, 130, 116, 33, 17, 51, 99, 98, 90, 55, 121, 94, 119, 43, 44, 43, 98, 47, 100, 112, 111, 34, 104, 7, 107, 55, 10, 11, 160, 26, 31, 25, 73, 3, 4, 70, 20, 21, 17, 79, 24, 64, 72, 13, 14, 86, 59, 17, 83, 56, 14, 13, 98, 135, 51, 25, 26, 1, 22, 72, 4, 3, 69, 42, 34, 49, 8, 64, 12, 11, 12, 55, 42, 9, 44, 39, 55, 21, 48, 109, 25, 17, 44, 67, 177, 29, 28, 31, 30, 25, 60, 27, 34, 38, 56, 31, 22, 17, 16, 19, 18, 129, 86, 47, 46, 5, 8, 43, 10, 79, 99, 73, 76, 75};
vector<int> ans;
if (M == 20) {
int il = M/20;
rep(i, il) {
for (auto x: pom) {
ans.pb(x);
}
}
}
else {
int il = M/500;
int c = 0;
rep(i, il) {
for (auto x: pom2) {
ans.pb(x);
}
// reverse(all(pom2));
}
}
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... |