제출 #1281594

#제출 시각아이디문제언어결과실행 시간메모리
1281594M_W_13Triple Peaks (IOI25_triples)C++20
82.75 / 100
162 ms43204 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, 1, 6, 5, 6, 3, 4, 5, 7, 1, 2, 15, 14, 17, 16, 12, 14, 9, 8, 11, 10, 25, 26, 25, 22, 29, 28, 19, 2, 19, 3, 23, 36, 35, 5, 33, 10, 11, 30, 9, 14, 45, 12, 47, 46, 47, 44, 49, 14, 41, 40, 3, 44, 43, 2, 35, 30, 11, 10, 51, 30, 65, 64, 33, 62, 39, 20, 71, 70, 21, 68, 25, 18, 65, 64, 21, 50, 9, 48, 11, 84, 83, 86, 85, 54, 83, 78, 39, 80, 79, 36, 1, 46, 45, 98, 97, 42, 29, 102, 69, 92, 99, 106, 35, 108, 107, 58, 105, 60, 55, 102, 57, 116, 117, 24, 85, 114, 21, 50, 111, 124, 123, 126, 69, 76, 123, 118, 37, 120, 39, 82, 77, 6, 79, 86, 109, 140, 107, 90, 91, 72, 51, 88, 133, 48, 19, 98, 21, 100, 95, 21, 61, 56, 15, 58, 65, 88, 19, 90, 33, 70, 67, 114, 37, 1, 27, 2, 77, 18, 43, 74, 3, 104, 35, 36, 37, 128, 51, 52, 41, 12, 17, 18, 93, 16, 59, 22, 61, 24, 21, 22, 53, 28, 55, 26, 3, 32, 33, 30, 31, 8, 75, 10, 5, 40, 7, 38, 69, 40, 11, 2, 19, 20, 21, 14, 15, 4, 49, 26, 11, 28, 9, 54, 25, 24, 5, 18, 38, 16, 1, 18, 1, 12, 1, 42, 37, 8, 7, 10, 9, 8, 7, 34, 13, 32, 13, 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); } // reverse(all(pom2)); } } 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...