제출 #1281593

#제출 시각아이디문제언어결과실행 시간메모리
1281593M_W_13Triple Peaks (IOI25_triples)C++20
82.20 / 100
162 ms43028 KiB
#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 = {1, 19, 3, 2, 53, 6, 5, 6, 7, 4, 5, 21, 1, 2, 15, 14, 17, 16, 61, 14, 9, 8, 11, 10, 25, 26, 25, 22, 29, 28, 19, 20, 17, 18, 23, 36, 35, 4, 33, 10, 11, 30, 9, 14, 45, 12, 47, 46, 47, 50, 1, 14, 41, 4, 3, 44, 43, 25, 45, 30, 11, 10, 33, 30, 65, 64, 33, 62, 11, 20, 71, 70, 21, 68, 97, 24, 65, 64, 21, 50, 9, 48, 11, 84, 83, 86, 85, 54, 83, 78, 39, 80, 79, 36, 1, 46, 45, 98, 69, 42, 29, 88, 69, 92, 91, 106, 35, 108, 107, 20, 61, 60, 55, 102, 57, 26, 117, 24, 23, 114, 21, 50, 111, 72, 91, 126, 69, 34, 123, 118, 51, 80, 39, 82, 77, 6, 79, 86, 109, 140, 139, 70, 91, 72, 51, 88, 53, 48, 19, 98, 21, 100, 81, 58, 61, 60, 15, 58, 65, 88, 103, 90, 33, 70, 69, 114, 67, 28, 27, 2, 41, 18, 43, 74, 41, 104, 35, 38, 37, 84, 51, 52, 41, 12, 95, 14, 93, 46, 59, 22, 61, 20, 3, 22, 53, 23, 55, 26, 33, 34, 33, 30, 31, 8, 75, 10, 9, 8, 70, 38, 69, 40, 19, 2, 19, 20, 17, 6, 15, 4, 13, 26, 11, 28, 9, 54, 11, 12, 5, 18, 7, 20, 1, 18, 1, 12, 3, 14, 1, 24, 7, 6, 9, 8, 7, 34, 13, 32, 15, 2}; vector<int> ans; if (M == 20) { int il = M/20; rep(i, il) { for (auto x: pom) { ans.pb(x); } } } else { int il = M/250; rep(i, il) { for (auto x: pom2) { ans.pb(x); } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...